home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / shadow-3.1.4 / log.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-05  |  1.6 KB  |  79 lines

  1. /*
  2.  * Copyright 1989, 1990, 1991, 1992, John F. Haugh II
  3.  * All rights reserved.
  4.  *
  5.  * Permission is granted to copy and create derivative works for any
  6.  * non-commercial purpose, provided this copyright notice is preserved
  7.  * in all copies of source code, or included in human readable form
  8.  * and conspicuously displayed on all copies of object code or
  9.  * distribution media.
  10.  */
  11.  
  12. #include <sys/types.h>
  13. #include <utmp.h>
  14. #include "pwd.h"
  15. #include <fcntl.h>
  16. #include <time.h>
  17. #ifndef    BSD
  18. #include <string.h>
  19. #include <memory.h>
  20. #else
  21. #include <strings.h>
  22. #define    strchr    index
  23. #define    strrchr    rindex
  24. #endif
  25. #include "config.h"
  26.  
  27. #ifndef    lint
  28. static    char    sccsid[] = "@(#)log.c    3.3    20:37:03    3/7/92";
  29. #endif
  30.  
  31. #include "lastlog.h"
  32.  
  33. #ifndef    LASTLOG_FILE
  34. #ifdef    SVR4
  35. #define    LASTLOG_FILE    "/var/adm/lastlog"
  36. #else
  37. #define    LASTLOG_FILE    "/usr/adm/lastlog"
  38. #endif    /* SVR4 */
  39. #endif    /* LASTLOG_FILE */
  40.  
  41. extern    struct    utmp    utent;
  42. extern    struct    passwd    pwent;
  43. extern    struct    lastlog    lastlog;
  44. extern    char    **environ;
  45.  
  46. long    lseek ();
  47. time_t    time ();
  48.  
  49. void    log ()
  50. {
  51.     int    fd;
  52.     off_t    offset;
  53.     struct    lastlog    newlog;
  54.  
  55.     if ((fd = open (LASTLOG_FILE, O_RDWR)) == -1)
  56.         return;
  57.  
  58.     offset = pwent.pw_uid * sizeof lastlog;
  59.  
  60.     if (lseek (fd, offset, 0) != offset) {
  61.         (void) close (fd);
  62.         return;
  63.     }
  64.     if (read (fd, (char *) &lastlog, sizeof lastlog) != sizeof lastlog)
  65. #ifndef    BSD
  66.         memset ((char *) &lastlog, sizeof lastlog, 0);
  67. #else
  68.         bzero ((char *) &lastlog, sizeof lastlog);
  69. #endif
  70.     newlog = lastlog;
  71.  
  72.     (void) time (&newlog.ll_time);
  73.     (void) strncpy (newlog.ll_line, utent.ut_line, sizeof newlog.ll_line);
  74.     (void) lseek (fd, offset, 0);
  75.     (void) write (fd, (char *) &newlog, sizeof newlog);
  76.     (void) close (fd);
  77. }
  78.  
  79.