… | |
… | |
33 | * You should have received a copy of the GNU General Public License |
33 | * You should have received a copy of the GNU General Public License |
34 | * along with this program; if not, write to the Free Software |
34 | * along with this program; if not, write to the Free Software |
35 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
35 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
36 | *----------------------------------------------------------------------*/ |
36 | *----------------------------------------------------------------------*/ |
37 | |
37 | |
38 | #include "../config.h" |
38 | #include "config.h" |
39 | |
39 | |
40 | #include "ptytty.h" |
40 | #include "ptytty.h" |
41 | |
41 | |
42 | #if UTMP_SUPPORT |
42 | #if UTMP_SUPPORT |
43 | |
43 | |
44 | #include <cstdio> |
44 | #include <cstdio> |
|
|
45 | #include <cstring> |
45 | |
46 | |
46 | #include <sys/types.h> |
47 | #include <sys/types.h> |
47 | #include <sys/stat.h> |
48 | #include <sys/stat.h> |
48 | #include <sys/fcntl.h> |
49 | #include <fcntl.h> |
49 | #include <unistd.h> |
50 | #include <unistd.h> |
50 | #include <time.h> |
51 | #include <time.h> |
|
|
52 | #include <errno.h> |
51 | |
53 | |
52 | /* |
54 | /* |
53 | * BSD style utmp entry |
55 | * BSD style utmp entry |
54 | * ut_line, ut_name, ut_host, ut_time |
56 | * ut_line, ut_name, ut_host, ut_time |
55 | * SYSV style utmp (and utmpx) entry |
57 | * SYSV style utmp (and utmpx) entry |
… | |
… | |
160 | strncpy (ll.ll_host, host, sizeof (ll.ll_host)); |
162 | strncpy (ll.ll_host, host, sizeof (ll.ll_host)); |
161 | if (stat (fname, &st) != 0) |
163 | if (stat (fname, &st) != 0) |
162 | return; |
164 | return; |
163 | if (S_ISDIR (st.st_mode)) |
165 | if (S_ISDIR (st.st_mode)) |
164 | { |
166 | { |
165 | sprintf (lastlogfile, "%.*s/%.*s", |
167 | snprintf (lastlogfile, sizeof (lastlogfile), "%s/%s", fname, |
166 | (int)(sizeof (lastlogfile) - sizeof (pwent->pw_name) - 2), fname, |
|
|
167 | (int)sizeof (pwent->pw_name), |
|
|
168 | (!pwent->pw_name || pwent->pw_name[0] == '\0') ? "unknown" |
168 | (!pwent->pw_name || pwent->pw_name[0] == '\0') ? "unknown" |
169 | : pwent->pw_name); |
169 | : pwent->pw_name); |
170 | if ((fd = open (lastlogfile, O_WRONLY | O_CREAT, 0644)) >= 0) |
170 | if ((fd = open (lastlogfile, O_WRONLY | O_CREAT, 0644)) >= 0) |
171 | { |
171 | { |
172 | write (fd, &ll, sizeof (ll)); |
172 | write (fd, &ll, sizeof (ll)); |