1 /************************************************************************
2 * Copyright 1995 by Wietse Venema. All rights reserved. Some individual
3 * files may be covered by other copyrights.
5 * This material was originally written and compiled by Wietse Venema at
6 * Eindhoven University of Technology, The Netherlands, in 1990, 1991,
7 * 1992, 1993, 1994 and 1995.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that this entire copyright notice
11 * is duplicated in all such copies.
13 * This software is provided "as is" and without any expressed or implied
14 * warranties, including, without limitation, the implied warranties of
15 * merchantibility and fitness for any particular purpose.
16 ************************************************************************/
17 /* Author: Wietse Venema <wietse@wzv.win.tue.nl> */
19 #include "login_locl.h"
21 __RCSID("$Heimdal: utmpx_login.c 10020 2001-06-04 14:10:19Z assar $"
24 /* utmpx_login - update utmp and wtmp after login */
27 int utmpx_login(char *line
, const char *user
, const char *host
) { return 0; }
31 utmpx_update(struct utmpx
*ut
, char *line
, const char *user
, const char *host
)
34 char *clean_tty
= clean_ttyname(line
);
36 strncpy(ut
->ut_line
, clean_tty
, sizeof(ut
->ut_line
));
37 #ifdef HAVE_STRUCT_UTMPX_UT_ID
38 strncpy(ut
->ut_id
, make_id(clean_tty
), sizeof(ut
->ut_id
));
40 strncpy(ut
->ut_user
, user
, sizeof(ut
->ut_user
));
41 shrink_hostname (host
, ut
->ut_host
, sizeof(ut
->ut_host
));
42 #ifdef HAVE_STRUCT_UTMPX_UT_SYSLEN
43 ut
->ut_syslen
= strlen(host
) + 1;
44 if (ut
->ut_syslen
> sizeof(ut
->ut_host
))
45 ut
->ut_syslen
= sizeof(ut
->ut_host
);
47 ut
->ut_type
= USER_PROCESS
;
48 gettimeofday (&tmp
, 0);
49 ut
->ut_tv
.tv_sec
= tmp
.tv_sec
;
50 ut
->ut_tv
.tv_usec
= tmp
.tv_usec
;
53 updwtmpx(WTMPX_FILE
, ut
);
54 #elif defined(WTMP_FILE)
59 prepare_utmp (&utmp
, line
, user
, host
);
60 if ((fd
= open(_PATH_WTMP
, O_WRONLY
|O_APPEND
, 0)) >= 0) {
61 write(fd
, &utmp
, sizeof(struct utmp
));
69 utmpx_login(char *line
, const char *user
, const char *host
)
71 struct utmpx
*ut
, save_ut
;
72 pid_t mypid
= getpid();
76 * SYSV4 ttymon and login use tty port names with the "/dev/" prefix
77 * stripped off. Rlogind and telnetd, on the other hand, make utmpx
78 * entries with device names like /dev/pts/nnn. We therefore cannot use
79 * getutxline(). Return nonzero if no utmp entry was found with our own
80 * process ID for a login or user process.
83 while ((ut
= getutxent())) {
84 /* Try to find a reusable entry */
85 if (ut
->ut_pid
== mypid
86 && ( ut
->ut_type
== INIT_PROCESS
87 || ut
->ut_type
== LOGIN_PROCESS
88 || ut
->ut_type
== USER_PROCESS
)) {
90 utmpx_update(&save_ut
, line
, user
, host
);
96 /* Grow utmpx file by one record. */
98 memset(&newut
, 0, sizeof(newut
));
100 utmpx_update(&newut
, line
, user
, host
);
106 #endif /* HAVE_UTMPX_H */