home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1989, 1990, John F. Haugh II
- * All rights reserved.
- *
- * Use, duplication, and disclosure prohibited without
- * the express written permission of the author.
- */
-
- #include <sys/types.h>
- #include <utmp.h>
- #include <pwd.h>
- #include <fcntl.h>
- #include <time.h>
- #ifndef BSD
- #include <string.h>
- #include <memory.h>
- #else
- #include <strings.h>
- #define strchr index
- #define strrchr rindex
- #endif
- #include "config.h"
-
- #ifndef lint
- static char _sccsid[] = "@(#)log.c 2.2 19:23:53 7/29/90";
- #endif
-
- #ifdef LASTLOG
-
- #include "lastlog.h"
-
- extern struct utmp utent;
- extern struct passwd pwent;
- extern struct lastlog lastlog;
- extern char **environ;
-
- long lseek ();
- time_t time ();
-
- void log ()
- {
- int fd;
- off_t 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) {
- (void) close (fd);
- return;
- }
- if (read (fd, (char *) &lastlog, sizeof lastlog) != sizeof lastlog)
- #ifndef BSD
- memset ((char *) &lastlog, sizeof lastlog, 0);
- #else
- bzero ((char *) &lastlog, sizeof lastlog);
- #endif
- 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
-