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

  1. /*
  2.  * Copyright 1991, 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. #ifndef lint
  13. static    char    sccsid[] = "@(#)logoutd.c    3.3    13:22:33    3/9/92";
  14. #endif
  15.  
  16. #include <sys/types.h>
  17. #include <stdio.h>
  18. #include <signal.h>
  19. #include <utmp.h>
  20. #include "config.h"
  21.  
  22. #ifdef SUN4
  23. #include <fcntl.h>
  24. #endif
  25.  
  26. main ()
  27. {
  28.     int    i;
  29.     struct    utmp    utmp;
  30.     int    fd;
  31. #if defined(BSD) || defined(SUN) || defined(SUN4)
  32.     char    tty_name[BUFSIZ];
  33.     int    tty_fd;
  34. #endif
  35.  
  36.     for (i = 0;close (i) == 0;i++)
  37.         ;
  38.  
  39. #ifdef    NDEBUG
  40. #ifdef    USG
  41.     setpgrp ();
  42. #endif
  43. #if defined(BSD) || defined(SUN) || defined(SUN4)
  44.     setpgid (getpid ());
  45. #endif
  46.     signal (SIGHUP, SIG_IGN);
  47.  
  48.     if (fork () > 0)
  49.         exit (0);
  50. #endif
  51.     while (1) {
  52. #ifdef    NDEBUG
  53.         sleep (60);
  54. #endif
  55.         if ((fd = open ("/etc/utmp", 0)) == -1)
  56.             continue;
  57.  
  58.         while (read (fd, &utmp, sizeof utmp) == sizeof utmp) {
  59. #ifdef    USG_UTMP
  60.             if (utmp.ut_type != USER_PROCESS)
  61.                 continue;
  62.             if (isttytime (utmp.ut_user, utmp.ut_line, time (0)))
  63.                 continue;
  64. #endif
  65. #ifdef BSD_UTMP
  66.             if (utmp.ut_name[0] == '\0')
  67.                 continue;
  68.             if (isttytime (utmp.ut_name, utmp.ut_line, time (0)))
  69.                 continue;
  70. #endif
  71. #ifdef    USG_UTMP
  72.             kill (- utmp.ut_pid, SIGHUP);
  73.             sleep (10);
  74.             kill (- utmp.ut_pid, SIGKILL);
  75. #endif
  76. #if defined(BSD) || defined(SUN) || defined(SUN4)
  77.  
  78.             /*
  79.              * vhangup() the line to kill try and kill
  80.              * whatever is out there using it.
  81.              */
  82.  
  83.             strcat (strcpy (tty_name, "/dev/"), utmp.ut_line);
  84.             if ((tty_fd = open (tty_name, O_RDONLY|O_NDELAY)) == -1)
  85.                 continue;
  86.  
  87.             vhangup (tty_fd);
  88.             close (tty_fd);
  89. #endif
  90.         }
  91.         close (fd);
  92.     }
  93. }
  94.