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"
23 /* utmpx_login - update utmp and wtmp after login */
26 int utmpx_login(char *line
, const char *user
, const char *host
) { return 0; }
30 utmpx_update(struct utmpx
*ut
, char *line
, const char *user
, const char *host
)
33 char *clean_tty
= clean_ttyname(line
);
35 strncpy(ut
->ut_line
, clean_tty
, sizeof(ut
->ut_line
));
36 #ifdef HAVE_STRUCT_UTMPX_UT_ID
37 strncpy(ut
->ut_id
, make_id(clean_tty
), sizeof(ut
->ut_id
));
39 strncpy(ut
->ut_user
, user
, sizeof(ut
->ut_user
));
40 shrink_hostname (host
, ut
->ut_host
, sizeof(ut
->ut_host
));
41 #ifdef HAVE_STRUCT_UTMPX_UT_SYSLEN
42 ut
->ut_syslen
= strlen(host
) + 1;
43 if (ut
->ut_syslen
> sizeof(ut
->ut_host
))
44 ut
->ut_syslen
= sizeof(ut
->ut_host
);
46 ut
->ut_type
= USER_PROCESS
;
47 gettimeofday (&tmp
, 0);
48 ut
->ut_tv
.tv_sec
= tmp
.tv_sec
;
49 ut
->ut_tv
.tv_usec
= tmp
.tv_usec
;
52 updwtmpx(WTMPX_FILE
, ut
);
53 #elif defined(WTMP_FILE)
54 { /* XXX should be removed, just drop wtmp support */
58 prepare_utmp (&utmp
, line
, user
, host
);
59 if ((fd
= open(_PATH_WTMP
, O_WRONLY
|O_APPEND
, 0)) >= 0) {
60 write(fd
, &utmp
, sizeof(struct utmp
));
68 utmpx_login(char *line
, const char *user
, const char *host
)
70 struct utmpx
*ut
, save_ut
;
71 pid_t mypid
= getpid();
75 * SYSV4 ttymon and login use tty port names with the "/dev/" prefix
76 * stripped off. Rlogind and telnetd, on the other hand, make utmpx
77 * entries with device names like /dev/pts/nnn. We therefore cannot use
78 * getutxline(). Return nonzero if no utmp entry was found with our own
79 * process ID for a login or user process.
82 while ((ut
= getutxent())) {
83 /* Try to find a reusable entry */
84 if (ut
->ut_pid
== mypid
85 && ( ut
->ut_type
== INIT_PROCESS
86 || ut
->ut_type
== LOGIN_PROCESS
87 || ut
->ut_type
== USER_PROCESS
)) {
89 utmpx_update(&save_ut
, line
, user
, host
);
95 /* Grow utmpx file by one record. */
97 memset(&newut
, 0, sizeof(newut
));
99 utmpx_update(&newut
, line
, user
, host
);
105 #endif /* HAVE_UTMPX_H */