home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / inetutils-1.2-src.tgz / tar.out / fsf / inetutils / libinetutils / cleansess.c next >
C/C++ Source or Header  |  1996-09-28  |  2KB  |  59 lines

  1. /* Clean up the pty and frob utmp/wtmp accordingly after logout
  2.  
  3.    Copyright (C) 1996 Free Software Foundation, Inc.
  4.  
  5.    Written by Miles Bader <miles@gnu.ai.mit.edu>
  6.  
  7.    This program is free software; you can redistribute it and/or
  8.    modify it under the terms of the GNU General Public License as
  9.    published by the Free Software Foundation; either version 2, or (at
  10.    your option) any later version.
  11.  
  12.    This program is distributed in the hope that it will be useful, but
  13.    WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.    General Public License for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License
  18.    along with this program; if not, write to the Free Software
  19.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #ifdef HAVE_CONFIG_H
  22. #include <config.h>
  23. #endif
  24.  
  25. #include <unistd.h>
  26. #include <sys/types.h>
  27. #include <sys/time.h>
  28. #ifdef HAVE_UTMP_H
  29. #include <utmp.h>
  30. #else
  31. #ifdef  HAVE_UTMPX_H
  32. #include <utmpx.h>
  33. #define utmp utmpx        /* make utmpx look more like utmp */
  34. #endif
  35. #endif
  36.  
  37. /* Update umtp & wtmp as necessary, and change tty & pty permissions back to
  38.    what they should be.  */
  39. void
  40. cleanup_session (char *tty, int pty_fd)
  41. {
  42.   char *line, *pty;
  43.  
  44. #ifdef PATH_TTY_PFX
  45.   if (strncmp (tty, PATH_TTY_PFX, sizeof PATH_TTY_PFX - 1) == 0)
  46.     line = tty + sizeof PATH_TTY_PFX - 1;
  47.   else
  48. #endif
  49.     line = tty;
  50.  
  51.   if (logout (line))
  52.     logwtmp (line, "", "");
  53.  
  54.   chmod (tty, 0666);
  55.   chown (tty, 0, 0);
  56.   fchmod (pty_fd, 0666);
  57.   fchown (pty_fd, 0, 0);
  58. }
  59.