home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume38 / shadow / part13 / sulog.c < prev    next >
C/C++ Source or Header  |  1993-08-14  |  2KB  |  70 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.  * This software is provided on an AS-IS basis and the author makes
  12.  * no warrantee of any kind.
  13.  */
  14.  
  15. #include <sys/types.h>
  16. #include <stdio.h>
  17. #include <time.h>
  18. #ifndef    BSD
  19. #include <string.h>
  20. #include <memory.h>
  21. #else
  22. #include <strings.h>
  23. #define    strchr    index
  24. #define    strrchr    rindex
  25. #endif
  26. #include "config.h"
  27.  
  28. #ifndef    lint
  29. static    char    sccsid[] = "@(#)sulog.c    3.3    13:02:53    27 Jul 1992";
  30. #endif
  31.  
  32. extern    char    name[];
  33. extern    char    oldname[];
  34.  
  35. time_t    time ();
  36. extern    char    *getdef_str();
  37.  
  38. /*
  39.  * sulog - log a SU command execution result
  40.  */
  41.  
  42. void
  43. sulog (tty, success)
  44. char    *tty;        /* Name of terminal SU was executed from */
  45. int    success;    /* Success (1) or failure (0) of command */
  46. {
  47.     char    *sulog;
  48.     char    *cp;
  49.     time_t    clock;
  50.     struct    tm    *tm;
  51.     struct    tm    *localtime ();
  52.     FILE    *fp;
  53.  
  54.     if ( (sulog=getdef_str("SULOG_FILE")) == (char *) 0 )
  55.         return;
  56.  
  57.     if ((fp = fopen (sulog, "a+")) == (FILE *) 0)
  58.         return;            /* can't open or create logfile */
  59.  
  60.     (void) time (&clock);
  61.     tm = localtime (&clock);
  62.  
  63.     (void) fprintf (fp, "SU %.02d/%0.2d %.02d:%.02d %c %.6s %s-%s\n",
  64.         tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min,
  65.         success ? '+':'-', tty, oldname, name);
  66.  
  67.     fflush (fp);
  68.     fclose (fp);
  69. }
  70.