| 1 |
/* cleansess.c - Clean up the pty and frob utmp/wtmp accordingly after logout |
| 2 |
Copyright (C) 1996-2026 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is part of GNU Inetutils. |
| 5 |
|
| 6 |
GNU Inetutils is free software: you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation, either version 3 of the License, or (at |
| 9 |
your option) any later version. |
| 10 |
|
| 11 |
GNU Inetutils is distributed in the hope that it will be useful, but |
| 12 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with this program. If not, see `http://www.gnu.org/licenses/'. */ |
| 18 |
|
| 19 |
/* Written by Miles Bader. */ |
| 20 |
|
| 21 |
#include <config.h> |
| 22 |
|
| 23 |
#include <unistd.h> |
| 24 |
#include <sys/types.h> |
| 25 |
#include <sys/time.h> |
| 26 |
#include <time.h> |
| 27 |
#ifdef HAVE_UTMP_H |
| 28 |
# ifdef HAVE_UTIL_H |
| 29 |
# include <util.h> |
| 30 |
# endif |
| 31 |
# ifdef HAVE_LIBUTIL_H |
| 32 |
# include <libutil.h> |
| 33 |
# endif |
| 34 |
# include <utmp.h> |
| 35 |
#else |
| 36 |
# ifdef HAVE_UTMPX_H |
| 37 |
# include <utmpx.h> |
| 38 |
# define utmp utmpx /* make utmpx look more like utmp */ |
| 39 |
# endif |
| 40 |
#endif |
| 41 |
#include <string.h> |
| 42 |
#include <sys/types.h> |
| 43 |
#include <sys/stat.h> |
| 44 |
|
| 45 |
#if defined HAVE_LOGOUT && HAVE_LOGWTMP |
| 46 |
|
| 47 |
/* Update umtp & wtmp as necessary, and change tty & pty permissions back to |
| 48 |
what they should be. */ |
| 49 |
void |
| 50 |
cleanup_session (char *tty, int pty_fd) |
| 51 |
{ |
| 52 |
char *line; |
| 53 |
|
| 54 |
# ifdef PATH_TTY_PFX |
| 55 |
if (strncmp (tty, PATH_TTY_PFX, sizeof PATH_TTY_PFX - 1) == 0) |
| 56 |
line = tty + sizeof PATH_TTY_PFX - 1; |
| 57 |
else |
| 58 |
# endif/* PATH_TTY_PFX */ |
| 59 |
line = tty; |
| 60 |
|
| 61 |
if (logout (line)) |
| 62 |
logwtmp (line, "", ""); |
| 63 |
|
| 64 |
lchmod (tty, 0666); |
| 65 |
lchown (tty, 0, 0); |
| 66 |
fchmod (pty_fd, 0666); |
| 67 |
fchown (pty_fd, 0, 0); |
| 68 |
} |
| 69 |
#endif /* HAVE_LOGOUT && HAVE_LOGWTMP */ |