1 /* Author: Wietse Venema <wietse@wzv.win.tue.nl> */
5 RCSID("$Id: utmpx_login.c,v 1.21 1999/03/29 17:57:31 joda Exp $");
7 /* utmpx_login - update utmp and wtmp after login */
10 int utmpx_login(char *line, char *user, char *host) { return 0; }
14 utmpx_update(struct utmpx *ut, char *line, char *user, char *host)
17 char *clean_tty = clean_ttyname(line);
19 strncpy(ut->ut_line, clean_tty, sizeof(ut->ut_line));
20 #ifdef HAVE_STRUCT_UTMPX_UT_ID
21 strncpy(ut->ut_id, make_id(clean_tty), sizeof(ut->ut_id));
23 strncpy(ut->ut_user, user, sizeof(ut->ut_user));
24 strncpy(ut->ut_host, host, sizeof(ut->ut_host));
25 #ifdef HAVE_STRUCT_UTMPX_UT_SYSLEN
26 ut->ut_syslen = strlen(host) + 1;
27 if (ut->ut_syslen > sizeof(ut->ut_host))
28 ut->ut_syslen = sizeof(ut->ut_host);
30 ut->ut_type = USER_PROCESS;
31 gettimeofday (&tmp, 0);
32 ut->ut_tv.tv_sec = tmp.tv_sec;
33 ut->ut_tv.tv_usec = tmp.tv_usec;
36 updwtmpx(WTMPX_FILE, ut);
37 #elif defined(WTMP_FILE)
42 prepare_utmp (&utmp, line, user, host);
43 if ((fd = open(_PATH_WTMP, O_WRONLY|O_APPEND, 0)) >= 0) {
44 write(fd, &utmp, sizeof(struct utmp));
52 utmpx_login(char *line, char *user, char *host)
55 pid_t mypid = getpid();
59 * SYSV4 ttymon and login use tty port names with the "/dev/" prefix
60 * stripped off. Rlogind and telnetd, on the other hand, make utmpx
61 * entries with device names like /dev/pts/nnn. We therefore cannot use
62 * getutxline(). Return nonzero if no utmp entry was found with our own
63 * process ID for a login or user process.
66 while ((ut = getutxent())) {
67 /* Try to find a reusable entry */
68 if (ut->ut_pid == mypid
69 && ( ut->ut_type == INIT_PROCESS
70 || ut->ut_type == LOGIN_PROCESS
71 || ut->ut_type == USER_PROCESS)) {
72 utmpx_update(ut, line, user, host);
78 /* Grow utmpx file by one record. */
80 memset(&newut, 0, sizeof(newut));
82 utmpx_update(&newut, line, user, host);
88 #endif /* HAVE_UTMPX_H */