home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2287 / log.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  1.3 KB  |  70 lines

  1. /*
  2.  * Copyright 1989, 1990, John F. Haugh II
  3.  * All rights reserved.
  4.  *
  5.  * Use, duplication, and disclosure prohibited without
  6.  * the express written permission of the author.
  7.  */
  8.  
  9. #include <sys/types.h>
  10. #include <utmp.h>
  11. #include <pwd.h>
  12. #include <fcntl.h>
  13. #include <time.h>
  14. #ifndef    BSD
  15. #include <string.h>
  16. #include <memory.h>
  17. #else
  18. #include <strings.h>
  19. #define    strchr    index
  20. #define    strrchr    rindex
  21. #endif
  22. #include "config.h"
  23.  
  24. #ifndef    lint
  25. static    char    _sccsid[] = "@(#)log.c    2.2    19:23:53    7/29/90";
  26. #endif
  27.  
  28. #ifdef    LASTLOG
  29.  
  30. #include "lastlog.h"
  31.  
  32. extern    struct    utmp    utent;
  33. extern    struct    passwd    pwent;
  34. extern    struct    lastlog    lastlog;
  35. extern    char    **environ;
  36.  
  37. long    lseek ();
  38. time_t    time ();
  39.  
  40. void    log ()
  41. {
  42.     int    fd;
  43.     off_t    offset;
  44.     struct    lastlog    newlog;
  45.  
  46.     if ((fd = open ("/usr/adm/lastlog", O_RDWR)) == -1)
  47.         return;
  48.  
  49.     offset = pwent.pw_uid * sizeof lastlog;
  50.  
  51.     if (lseek (fd, offset, 0) != offset) {
  52.         (void) close (fd);
  53.         return;
  54.     }
  55.     if (read (fd, (char *) &lastlog, sizeof lastlog) != sizeof lastlog)
  56. #ifndef    BSD
  57.         memset ((char *) &lastlog, sizeof lastlog, 0);
  58. #else
  59.         bzero ((char *) &lastlog, sizeof lastlog);
  60. #endif
  61.     newlog = lastlog;
  62.  
  63.     (void) time (&newlog.ll_time);
  64.     (void) strncpy (newlog.ll_line, utent.ut_line, sizeof newlog.ll_line);
  65.     (void) lseek (fd, offset, 0);
  66.     (void) write (fd, (char *) &newlog, sizeof newlog);
  67.     (void) close (fd);
  68. }
  69. #endif
  70.