… | |
… | |
37 | * |
37 | * |
38 | * Private: |
38 | * Private: |
39 | * rxvt_update_wtmp (); |
39 | * rxvt_update_wtmp (); |
40 | *----------------------------------------------------------------------*/ |
40 | *----------------------------------------------------------------------*/ |
41 | |
41 | |
42 | #include "../config.h" /* NECESSARY */ |
42 | #include "../config.h" |
43 | #include "rxvt.h" /* NECESSARY */ |
43 | #include "rxvt.h" |
44 | #include "logging.h" |
44 | #include "logging.h" |
|
|
45 | |
45 | #ifdef UTMP_SUPPORT |
46 | #ifdef UTMP_SUPPORT |
|
|
47 | |
|
|
48 | #if HAVE_STRUCT_UTMP |
|
|
49 | int rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu); |
|
|
50 | void rxvt_update_wtmp (const char *fname, const struct utmp *putmp); |
|
|
51 | #endif |
|
|
52 | |
|
|
53 | void rxvt_update_lastlog (const char *fname, const char *pty, const char *host); |
46 | |
54 | |
47 | /* |
55 | /* |
48 | * BSD style utmp entry |
56 | * BSD style utmp entry |
49 | * ut_line, ut_name, ut_host, ut_time |
57 | * ut_line, ut_name, ut_host, ut_time |
50 | * SYSV style utmp (and utmpx) entry |
58 | * SYSV style utmp (and utmpx) entry |
… | |
… | |
58 | */ |
66 | */ |
59 | void |
67 | void |
60 | rxvt_term::makeutent (const char *pty, const char *hostname) |
68 | rxvt_term::makeutent (const char *pty, const char *hostname) |
61 | { |
69 | { |
62 | #ifdef HAVE_STRUCT_UTMP |
70 | #ifdef HAVE_STRUCT_UTMP |
63 | struct utmp *ut = & (this->ut); |
71 | struct utmp *ut = &this->ut; |
64 | #endif |
72 | #endif |
65 | #ifdef HAVE_STRUCT_UTMPX |
73 | #ifdef HAVE_STRUCT_UTMPX |
66 | struct utmpx *utx = & (this->utx); |
74 | struct utmpx *utx = &this->utx; |
67 | #endif |
75 | #endif |
68 | #ifdef HAVE_UTMP_PID |
76 | #ifdef HAVE_UTMP_PID |
69 | int i; |
77 | int i; |
70 | #endif |
78 | #endif |
71 | char ut_id[5]; |
|
|
72 | struct passwd *pwent = getpwuid (getuid ()); |
79 | struct passwd *pwent = getpwuid (getuid ()); |
73 | |
80 | |
74 | if (!STRNCMP (pty, "/dev/", 5)) |
81 | if (!strncmp (pty, "/dev/", 5)) |
75 | pty += 5; /* skip /dev/ prefix */ |
82 | pty += 5; /* skip /dev/ prefix */ |
76 | |
83 | |
77 | if (!STRNCMP (pty, "pty", 3) || !STRNCMP (pty, "tty", 3)) |
|
|
78 | { |
|
|
79 | STRNCPY (ut_id, (pty + 3), sizeof (ut_id)); |
|
|
80 | } |
|
|
81 | #ifdef HAVE_UTMP_PID |
84 | #ifdef HAVE_UTMP_PID |
|
|
85 | if (!strncmp (pty, "pty", 3) || !strncmp (pty, "tty", 3)) |
|
|
86 | strncpy (ut_id, pty + 3, sizeof (ut_id)); |
82 | else if (sscanf (pty, "pts/%d", &i) == 1) |
87 | else if (sscanf (pty, "pts/%d", &i) == 1) |
83 | sprintf (ut_id, "vt%02x", (i & 0xff)); /* sysv naming */ |
88 | sprintf (ut_id, "vt%02x", (i & 0xff)); /* sysv naming */ |
84 | #endif |
|
|
85 | else if (STRNCMP (pty, "pty", 3) && STRNCMP (pty, "tty", 3)) |
89 | else if (strncmp (pty, "pty", 3) && strncmp (pty, "tty", 3)) |
86 | { |
90 | { |
87 | rxvt_warn ("can't parse tty name \"%s\", not adding utmp entry.\n", pty); |
91 | rxvt_warn ("can't parse tty name \"%s\", not adding utmp entry.\n", pty); |
88 | return; |
92 | return; |
89 | } |
93 | } |
|
|
94 | #endif |
90 | |
95 | |
91 | #ifdef HAVE_STRUCT_UTMP |
96 | #ifdef HAVE_STRUCT_UTMP |
92 | MEMSET (ut, 0, sizeof (struct utmp)); |
97 | memset (ut, 0, sizeof (struct utmp)); |
93 | # ifdef HAVE_UTMP_PID |
98 | # ifdef HAVE_UTMP_PID |
94 | setutent (); |
99 | setutent (); |
95 | STRNCPY (ut->ut_id, ut_id, sizeof (ut->ut_id)); |
100 | strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id)); |
96 | ut->ut_type = DEAD_PROCESS; |
101 | ut->ut_type = DEAD_PROCESS; |
97 | getutid (ut); /* position to entry in utmp file */ |
102 | getutid (ut); /* position to entry in utmp file */ |
98 | STRNCPY (ut_id, ut_id, sizeof (ut_id)); |
103 | strncpy (this->ut_id, ut_id, sizeof (this->ut_id)); |
99 | # endif |
|
|
100 | #endif |
104 | # endif |
|
|
105 | #endif |
101 | |
106 | |
102 | #ifdef HAVE_STRUCT_UTMPX |
107 | #ifdef HAVE_STRUCT_UTMPX |
103 | MEMSET (utx, 0, sizeof (struct utmpx)); |
108 | memset (utx, 0, sizeof (struct utmpx)); |
104 | setutxent (); |
109 | setutxent (); |
105 | STRNCPY (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
110 | strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
106 | utx->ut_type = DEAD_PROCESS; |
111 | utx->ut_type = DEAD_PROCESS; |
107 | getutxid (utx); /* position to entry in utmp file */ |
112 | getutxid (utx); /* position to entry in utmp file */ |
108 | STRNCPY (ut_id, ut_id, sizeof (ut_id)); |
113 | strncpy (this->ut_id, ut_id, sizeof (this->ut_id)); |
109 | #endif |
114 | #endif |
110 | |
115 | |
111 | #ifdef HAVE_STRUCT_UTMP |
116 | #ifdef HAVE_STRUCT_UTMP |
112 | STRNCPY (ut->ut_line, pty, sizeof (ut->ut_line)); |
117 | strncpy (ut->ut_line, pty, sizeof (ut->ut_line)); |
113 | ut->ut_time = time (NULL); |
118 | ut->ut_time = time (NULL); |
114 | # ifdef HAVE_UTMP_PID |
119 | # ifdef HAVE_UTMP_PID |
115 | STRNCPY (ut->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?", |
120 | strncpy (ut->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?", |
116 | sizeof (ut->ut_user)); |
121 | sizeof (ut->ut_user)); |
117 | STRNCPY (ut->ut_id, ut_id, sizeof (ut->ut_id)); |
122 | strncpy (ut->ut_id, ut_id, sizeof (ut->ut_id)); |
118 | ut->ut_time = time (NULL); |
123 | ut->ut_time = time (NULL); |
119 | ut->ut_pid = cmd_pid; |
124 | ut->ut_pid = cmd_pid; |
120 | # ifdef HAVE_UTMP_HOST |
125 | # ifdef HAVE_UTMP_HOST |
121 | STRNCPY (ut->ut_host, hostname, sizeof (ut->ut_host)); |
126 | strncpy (ut->ut_host, hostname, sizeof (ut->ut_host)); |
122 | # endif |
127 | # endif |
123 | ut->ut_type = USER_PROCESS; |
128 | ut->ut_type = USER_PROCESS; |
124 | pututline (ut); |
129 | pututline (ut); |
125 | endutent (); /* close the file */ |
130 | endutent (); /* close the file */ |
126 | utmp_pos = 0; |
131 | utmp_pos = 0; |
127 | # else |
132 | # else |
128 | STRNCPY (ut->ut_name, (pwent && pwent->pw_name) ? pwent->pw_name : "?", |
133 | strncpy (ut->ut_name, (pwent && pwent->pw_name) ? pwent->pw_name : "?", |
129 | sizeof (ut->ut_name)); |
134 | sizeof (ut->ut_name)); |
130 | # ifdef HAVE_UTMP_HOST |
135 | # ifdef HAVE_UTMP_HOST |
131 | STRNCPY (ut->ut_host, hostname, sizeof (ut->ut_host)); |
136 | strncpy (ut->ut_host, hostname, sizeof (ut->ut_host)); |
132 | # endif |
|
|
133 | # endif |
137 | # endif |
134 | #endif |
138 | # endif |
|
|
139 | #endif |
135 | |
140 | |
136 | #ifdef HAVE_STRUCT_UTMPX |
141 | #ifdef HAVE_STRUCT_UTMPX |
137 | STRNCPY (utx->ut_line, pty, sizeof (utx->ut_line)); |
142 | strncpy (utx->ut_line, pty, sizeof (utx->ut_line)); |
138 | STRNCPY (utx->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?", |
143 | strncpy (utx->ut_user, (pwent && pwent->pw_name) ? pwent->pw_name : "?", |
139 | sizeof (utx->ut_user)); |
144 | sizeof (utx->ut_user)); |
140 | STRNCPY (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
145 | strncpy (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
|
|
146 | # if HAVE_UTMPX_SESSION |
141 | utx->ut_session = getsid (0); |
147 | utx->ut_session = getsid (0); |
|
|
148 | # endif |
142 | utx->ut_tv.tv_sec = time (NULL); |
149 | utx->ut_tv.tv_sec = time (NULL); |
143 | utx->ut_tv.tv_usec = 0; |
150 | utx->ut_tv.tv_usec = 0; |
144 | utx->ut_pid = cmd_pid; |
151 | utx->ut_pid = cmd_pid; |
145 | # ifdef HAVE_UTMPX_HOST |
152 | # ifdef HAVE_UTMPX_HOST |
146 | STRNCPY (utx->ut_host, hostname, sizeof (utx->ut_host)); |
153 | strncpy (utx->ut_host, hostname, sizeof (utx->ut_host)); |
147 | # if 0 |
154 | # if 0 |
148 | { |
155 | { |
149 | char *colon; |
156 | char *colon; |
150 | |
157 | |
151 | if ((colon = STRRCHR (ut->ut_host, ':')) != NULL) |
158 | if ((colon = strrchr (ut->ut_host, ':')) != NULL) |
152 | *colon = '\0'; |
159 | *colon = '\0'; |
153 | } |
160 | } |
154 | # endif |
161 | # endif |
155 | # endif |
162 | # endif |
156 | utx->ut_type = USER_PROCESS; |
163 | utx->ut_type = USER_PROCESS; |
… | |
… | |
170 | # else |
177 | # else |
171 | FILE *fd0; |
178 | FILE *fd0; |
172 | |
179 | |
173 | if ((fd0 = fopen (TTYTAB_FILENAME, "r")) != NULL) |
180 | if ((fd0 = fopen (TTYTAB_FILENAME, "r")) != NULL) |
174 | { |
181 | { |
175 | char buf[256], name[256]; |
182 | char buf[256], name[256]; |
176 | |
183 | |
177 | buf[sizeof (buf) - 1] = '\0'; |
184 | buf[sizeof (buf) - 1] = '\0'; |
178 | for (i = 1; (fgets (buf, sizeof (buf) - 1, fd0) != NULL);) |
185 | for (i = 1; (fgets (buf, sizeof (buf) - 1, fd0) != NULL);) |
179 | { |
186 | { |
180 | if (*buf == '#' || sscanf (buf, "%s", name) != 1) |
187 | if (*buf == '#' || sscanf (buf, "%s", name) != 1) |
181 | continue; |
188 | continue; |
182 | if (!STRCMP (ut->ut_line, name)) |
189 | if (!strcmp (ut->ut_line, name)) |
183 | { |
190 | { |
184 | if (!rxvt_write_bsd_utmp (i, ut)) |
191 | if (!rxvt_write_bsd_utmp (i, ut)) |
185 | i = 0; |
192 | i = 0; |
186 | utmp_pos = i; |
193 | utmp_pos = i; |
187 | fclose (fd0); |
194 | fclose (fd0); |
… | |
… | |
196 | } |
203 | } |
197 | #endif |
204 | #endif |
198 | |
205 | |
199 | #ifdef WTMP_SUPPORT |
206 | #ifdef WTMP_SUPPORT |
200 | # ifdef WTMP_ONLY_ON_LOGIN |
207 | # ifdef WTMP_ONLY_ON_LOGIN |
201 | if (Options & Opt_loginShell) |
208 | if (OPTION (Opt_loginShell)) |
202 | # endif |
209 | # endif |
203 | { |
210 | { |
204 | # ifdef HAVE_STRUCT_UTMP |
211 | # ifdef HAVE_STRUCT_UTMP |
205 | # ifdef HAVE_UPDWTMP |
212 | # ifdef HAVE_UPDWTMP |
206 | updwtmp (RXVT_WTMP_FILE, ut); |
213 | updwtmp (RXVT_WTMP_FILE, ut); |
207 | # else |
214 | # else |
208 | rxvt_update_wtmp (RXVT_WTMP_FILE, ut); |
215 | rxvt_update_wtmp (RXVT_WTMP_FILE, ut); |
209 | # endif |
216 | # endif |
210 | # endif |
217 | # endif |
211 | # ifdef HAVE_STRUCT_UTMPX |
218 | # ifdef HAVE_STRUCT_UTMPX |
|
|
219 | # if HAVE_UPDWTMPX |
212 | updwtmpx (RXVT_WTMPX_FILE, utx); |
220 | updwtmpx (RXVT_WTMPX_FILE, utx); |
|
|
221 | # else |
|
|
222 | pututxline (utx); |
|
|
223 | # endif |
213 | # endif |
224 | # endif |
214 | } |
225 | } |
215 | #endif |
226 | #endif |
216 | #if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE) |
227 | #if defined(LASTLOG_SUPPORT) && defined(RXVT_LASTLOG_FILE) |
217 | if (Options & Opt_loginShell) |
228 | if (OPTION (Opt_loginShell)) |
218 | rxvt_update_lastlog (RXVT_LASTLOG_FILE, pty, hostname); |
229 | rxvt_update_lastlog (RXVT_LASTLOG_FILE, pty, hostname); |
219 | #endif |
230 | #endif |
220 | } |
231 | } |
221 | |
232 | |
222 | /* ------------------------------------------------------------------------- */ |
233 | /* ------------------------------------------------------------------------- */ |
… | |
… | |
225 | */ |
236 | */ |
226 | void |
237 | void |
227 | rxvt_term::cleanutent () |
238 | rxvt_term::cleanutent () |
228 | { |
239 | { |
229 | #ifdef HAVE_STRUCT_UTMP |
240 | #ifdef HAVE_STRUCT_UTMP |
230 | struct utmp *ut = & (this->ut); |
241 | struct utmp *ut = &this->ut; |
231 | #endif |
242 | #endif |
232 | #ifdef HAVE_STRUCT_UTMPX |
243 | #ifdef HAVE_STRUCT_UTMPX |
233 | struct utmpx *tmputx, *utx = & (this->utx); |
244 | struct utmpx *tmputx, *utx = &this->utx; |
234 | #endif |
245 | #endif |
235 | |
246 | |
236 | #ifdef HAVE_STRUCT_UTMP |
247 | #ifdef HAVE_STRUCT_UTMP |
237 | # ifdef HAVE_UTMP_PID |
248 | # ifdef HAVE_UTMP_PID |
238 | MEMSET (ut, 0, sizeof (struct utmp)); |
249 | memset (ut, 0, sizeof (struct utmp)); |
239 | setutent (); |
250 | setutent (); |
240 | STRNCPY (ut->ut_id, ut_id, sizeof (ut->ut_id)); |
251 | strncpy (ut->ut_id, this->ut_id, sizeof (ut->ut_id)); |
241 | ut->ut_type = USER_PROCESS; |
252 | ut->ut_type = USER_PROCESS; |
242 | { |
253 | { |
243 | struct utmp *tmput = getutid (ut); |
254 | struct utmp *tmput = getutid (ut); |
244 | |
255 | |
245 | if (tmput) /* position to entry in utmp file */ |
256 | if (tmput) /* position to entry in utmp file */ |
246 | ut = tmput; |
257 | ut = tmput; |
247 | } |
258 | } |
248 | ut->ut_type = DEAD_PROCESS; |
259 | ut->ut_type = DEAD_PROCESS; |
249 | # else |
260 | # else |
250 | MEMSET (ut->ut_name, 0, sizeof (ut->ut_name)); |
261 | memset (ut->ut_name, 0, sizeof (ut->ut_name)); |
251 | # ifdef HAVE_UTMP_HOST |
262 | # ifdef HAVE_UTMP_HOST |
252 | MEMSET (ut->ut_host, 0, sizeof (ut->ut_host)); |
263 | memset (ut->ut_host, 0, sizeof (ut->ut_host)); |
253 | # endif |
264 | # endif |
254 | # endif |
265 | # endif |
255 | ut->ut_time = time (NULL); |
266 | ut->ut_time = time (NULL); |
256 | #endif |
267 | #endif |
257 | |
268 | |
258 | #ifdef HAVE_STRUCT_UTMPX |
269 | #ifdef HAVE_STRUCT_UTMPX |
259 | MEMSET (utx, 0, sizeof (struct utmpx)); |
270 | memset (utx, 0, sizeof (struct utmpx)); |
260 | setutxent (); |
271 | setutxent (); |
261 | STRNCPY (utx->ut_id, ut_id, sizeof (utx->ut_id)); |
272 | strncpy (utx->ut_id, this->ut_id, sizeof (utx->ut_id)); |
262 | utx->ut_type = USER_PROCESS; |
273 | utx->ut_type = USER_PROCESS; |
263 | if ((tmputx = getutxid (utx))) /* position to entry in utmp file */ |
274 | if ((tmputx = getutxid (utx))) /* position to entry in utmp file */ |
264 | utx = tmputx; |
275 | utx = tmputx; |
265 | utx->ut_type = DEAD_PROCESS; |
276 | utx->ut_type = DEAD_PROCESS; |
|
|
277 | # if HAVE_UTMPX_SESSION |
266 | utx->ut_session = getsid (0); |
278 | utx->ut_session = getsid (0); |
|
|
279 | # endif |
267 | utx->ut_tv.tv_sec = time (NULL); |
280 | utx->ut_tv.tv_sec = time (NULL); |
268 | utx->ut_tv.tv_usec = 0; |
281 | utx->ut_tv.tv_usec = 0; |
269 | #endif |
282 | #endif |
270 | |
283 | |
271 | /* |
284 | /* |
272 | * Write ending wtmp entry |
285 | * Write ending wtmp entry |
273 | */ |
286 | */ |
274 | #ifdef WTMP_SUPPORT |
287 | #ifdef WTMP_SUPPORT |
275 | # ifdef WTMP_ONLY_ON_LOGIN |
288 | # ifdef WTMP_ONLY_ON_LOGIN |
276 | if (Options & Opt_loginShell) |
289 | if (OPTION (Opt_loginShell)) |
277 | # endif |
290 | # endif |
278 | { |
291 | { |
279 | # ifdef HAVE_STRUCT_UTMP |
292 | # ifdef HAVE_STRUCT_UTMP |
280 | # ifdef HAVE_UPDWTMP |
293 | # ifdef HAVE_UPDWTMP |
281 | updwtmp (RXVT_WTMP_FILE, ut); |
294 | updwtmp (RXVT_WTMP_FILE, ut); |
282 | # else |
295 | # else |
283 | rxvt_update_wtmp (RXVT_WTMP_FILE, ut); |
296 | rxvt_update_wtmp (RXVT_WTMP_FILE, ut); |
284 | # endif |
297 | # endif |
285 | # endif |
298 | # endif |
286 | # ifdef HAVE_STRUCT_UTMPX |
299 | # ifdef HAVE_STRUCT_UTMPX |
|
|
300 | # if HAVE_UPDWTMPX |
287 | updwtmpx (RXVT_WTMPX_FILE, utx); |
301 | updwtmpx (RXVT_WTMPX_FILE, utx); |
|
|
302 | # else |
|
|
303 | pututxline (utx); |
|
|
304 | # endif |
288 | # endif |
305 | # endif |
289 | } |
306 | } |
290 | #endif |
307 | #endif |
291 | |
308 | |
292 | /* |
309 | /* |
… | |
… | |
296 | # ifdef HAVE_UTMP_PID |
313 | # ifdef HAVE_UTMP_PID |
297 | if (ut->ut_pid == cmd_pid) |
314 | if (ut->ut_pid == cmd_pid) |
298 | pututline (ut); |
315 | pututline (ut); |
299 | endutent (); |
316 | endutent (); |
300 | # else |
317 | # else |
301 | MEMSET (ut, 0, sizeof (struct utmp)); |
318 | memset (ut, 0, sizeof (struct utmp)); |
302 | rxvt_write_bsd_utmp (utmp_pos, ut); |
319 | rxvt_write_bsd_utmp (utmp_pos, ut); |
303 | # endif |
320 | # endif |
304 | #endif |
321 | #endif |
305 | #ifdef HAVE_STRUCT_UTMPX |
322 | #ifdef HAVE_STRUCT_UTMPX |
306 | if (utx->ut_pid == cmd_pid) |
323 | if (utx->ut_pid == cmd_pid) |
… | |
… | |
312 | /* ------------------------------------------------------------------------- */ |
329 | /* ------------------------------------------------------------------------- */ |
313 | /* |
330 | /* |
314 | * Write a BSD style utmp entry |
331 | * Write a BSD style utmp entry |
315 | */ |
332 | */ |
316 | #ifdef HAVE_UTMP_H |
333 | #ifdef HAVE_UTMP_H |
317 | /* INTPROTO */ |
|
|
318 | int |
334 | int |
319 | rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu) |
335 | rxvt_write_bsd_utmp (int utmp_pos, struct utmp *wu) |
320 | { |
336 | { |
321 | int fd; |
337 | int fd; |
322 | |
338 | |
… | |
… | |
332 | |
348 | |
333 | /* ------------------------------------------------------------------------- */ |
349 | /* ------------------------------------------------------------------------- */ |
334 | /* |
350 | /* |
335 | * Update a BSD style wtmp entry |
351 | * Update a BSD style wtmp entry |
336 | */ |
352 | */ |
337 | #if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) |
353 | #if defined(WTMP_SUPPORT) && !defined(HAVE_UPDWTMP) && defined(HAVE_STRUCT_UTMP) |
338 | /* INTPROTO */ |
|
|
339 | void |
354 | void |
340 | rxvt_update_wtmp (const char *fname, const struct utmp *putmp) |
355 | rxvt_update_wtmp (const char *fname, const struct utmp *putmp) |
341 | { |
356 | { |
342 | int fd, gotlock, retry; |
357 | int fd, gotlock, retry; |
343 | struct flock lck; /* fcntl locking scheme */ |
358 | struct flock lck; /* fcntl locking scheme */ |
… | |
… | |
375 | } |
390 | } |
376 | #endif |
391 | #endif |
377 | |
392 | |
378 | /* ------------------------------------------------------------------------- */ |
393 | /* ------------------------------------------------------------------------- */ |
379 | #ifdef LASTLOG_SUPPORT |
394 | #ifdef LASTLOG_SUPPORT |
380 | /* INTPROTO */ |
|
|
381 | void |
395 | void |
382 | rxvt_update_lastlog (const char *fname, const char *pty, const char *host) |
396 | rxvt_update_lastlog (const char *fname, const char *pty, const char *host) |
383 | { |
397 | { |
384 | # ifdef HAVE_STRUCT_LASTLOGX |
398 | # ifdef HAVE_STRUCT_LASTLOGX |
385 | struct lastlogx llx; |
399 | struct lastlogx llx; |
… | |
… | |
392 | # endif |
406 | # endif |
393 | struct passwd *pwent; |
407 | struct passwd *pwent; |
394 | # endif |
408 | # endif |
395 | |
409 | |
396 | # ifdef HAVE_STRUCT_LASTLOGX |
410 | # ifdef HAVE_STRUCT_LASTLOGX |
397 | MEMSET (&llx, 0, sizeof (llx)); |
411 | memset (&llx, 0, sizeof (llx)); |
398 | llx.ll_tv.tv_sec = time (NULL); |
412 | llx.ll_tv.tv_sec = time (NULL); |
399 | llx.ll_tv.tv_usec = 0; |
413 | llx.ll_tv.tv_usec = 0; |
400 | STRNCPY (llx.ll_line, pty, sizeof (llx.ll_line)); |
414 | strncpy (llx.ll_line, pty, sizeof (llx.ll_line)); |
401 | STRNCPY (llx.ll_host, host, sizeof (llx.ll_host)); |
415 | strncpy (llx.ll_host, host, sizeof (llx.ll_host)); |
402 | updlastlogx (RXVT_LASTLOGX_FILE, getuid (), &llx); |
416 | updlastlogx (RXVT_LASTLOGX_FILE, getuid (), &llx); |
403 | # endif |
417 | # endif |
404 | |
418 | |
405 | # ifdef HAVE_STRUCT_LASTLOG |
419 | # ifdef HAVE_STRUCT_LASTLOG |
406 | pwent = getpwuid (getuid ()); |
420 | pwent = getpwuid (getuid ()); |
… | |
… | |
408 | { |
422 | { |
409 | rxvt_warn ("no entry in password file, not updating lastlog.\n"); |
423 | rxvt_warn ("no entry in password file, not updating lastlog.\n"); |
410 | return; |
424 | return; |
411 | } |
425 | } |
412 | |
426 | |
413 | MEMSET (&ll, 0, sizeof (ll)); |
427 | memset (&ll, 0, sizeof (ll)); |
414 | ll.ll_time = time (NULL); |
428 | ll.ll_time = time (NULL); |
415 | STRNCPY (ll.ll_line, pty, sizeof (ll.ll_line)); |
429 | strncpy (ll.ll_line, pty, sizeof (ll.ll_line)); |
416 | STRNCPY (ll.ll_host, host, sizeof (ll.ll_host)); |
430 | strncpy (ll.ll_host, host, sizeof (ll.ll_host)); |
417 | # ifdef LASTLOG_IS_DIR |
431 | # ifdef LASTLOG_IS_DIR |
418 | sprintf (lastlogfile, "%.*s/%.*s", |
432 | sprintf (lastlogfile, "%.*s/%.*s", |
419 | sizeof (lastlogfile) - sizeof (pwent->pw_name) - 2, fname, |
433 | sizeof (lastlogfile) - sizeof (pwent->pw_name) - 2, fname, |
420 | sizeof (pwent->pw_name), |
434 | sizeof (pwent->pw_name), |
421 | (!pwent->pw_name || pwent->pw_name[0] == '\0') ? "unknown" |
435 | (!pwent->pw_name || pwent->pw_name[0] == '\0') ? "unknown" |