home *** CD-ROM | disk | FTP | other *** search
- #include <sys/types.h>
- #include <utmp.h>
- #include <pwd.h>
- #include <fcntl.h>
- #include <time.h>
- #include <string.h>
- #include "config.h"
-
- extern struct utmp utent;
- extern struct passwd pwent;
- extern struct lastlog lastlog;
- extern char **environ;
-
- long lseek ();
- time_t time ();
-
- #ifdef LASTLOG
-
- #include "lastlog.h"
-
- void log ()
- {
- int fd;
- long offset;
- struct lastlog newlog;
-
- if ((fd = open ("/usr/adm/lastlog", O_RDWR)) == -1)
- return;
-
- offset = pwent.pw_uid * sizeof lastlog;
-
- if (lseek (fd, offset, 0) != offset)
- return;
-
- if (read (fd, (char *) &lastlog, sizeof lastlog) != sizeof lastlog)
- memset ((char *) &lastlog, sizeof lastlog, 0);
-
- newlog = lastlog;
-
- (void) time (&newlog.ll_time);
- (void) strncpy (newlog.ll_line, utent.ut_line, sizeof newlog.ll_line);
- (void) lseek (fd, offset, 0);
- (void) write (fd, (char *) &newlog, sizeof newlog);
- (void) close (fd);
- }
- #endif
-