home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3349 / log.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-17  |  1.5 KB  |  73 lines

  1. /*
  2.  * Copyright 1989, 1990, 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.1    12:30:53    12/12/90";
  29. #endif
  30.  
  31. #ifdef    LASTLOG
  32.  
  33. #include "lastlog.h"
  34.  
  35. extern    struct    utmp    utent;
  36. extern    struct    passwd    pwent;
  37. extern    struct    lastlog    lastlog;
  38. extern    char    **environ;
  39.  
  40. long    lseek ();
  41. time_t    time ();
  42.  
  43. void    log ()
  44. {
  45.     int    fd;
  46.     off_t    offset;
  47.     struct    lastlog    newlog;
  48.  
  49.     if ((fd = open ("/usr/adm/lastlog", O_RDWR)) == -1)
  50.         return;
  51.  
  52.     offset = pwent.pw_uid * sizeof lastlog;
  53.  
  54.     if (lseek (fd, offset, 0) != offset) {
  55.         (void) close (fd);
  56.         return;
  57.     }
  58.     if (read (fd, (char *) &lastlog, sizeof lastlog) != sizeof lastlog)
  59. #ifndef    BSD
  60.         memset ((char *) &lastlog, sizeof lastlog, 0);
  61. #else
  62.         bzero ((char *) &lastlog, sizeof lastlog);
  63. #endif
  64.     newlog = lastlog;
  65.  
  66.     (void) time (&newlog.ll_time);
  67.     (void) strncpy (newlog.ll_line, utent.ut_line, sizeof newlog.ll_line);
  68.     (void) lseek (fd, offset, 0);
  69.     (void) write (fd, (char *) &newlog, sizeof newlog);
  70.     (void) close (fd);
  71. }
  72. #endif
  73.