/*
* Global variables
*/
-static char *Prog;
+const char *Prog;
#ifndef DEFAULT_HUP_MESG
#define DEFAULT_HUP_MESG _("login time exceeded\n\n")
#define HUP_MESG_FILE "/etc/logoutd.mesg"
#endif
-#if HAVE_UTMPX_H
-static int check_login (const struct utmpx *);
-#else
-static int check_login (const struct utmp *);
-#endif
+/* local function prototypes */
+#ifdef USE_UTMPX
+static int check_login (const struct utmpx *ut);
+#else /* !USE_UTMPX */
+static int check_login (const struct utmp *ut);
+#endif /* !USE_UTMPX */
+static void send_mesg_to_tty (int tty_fd);
/*
* check_login - check if user (struct utmpx/utmp) allowed to stay logged in
*/
-#if HAVE_UTMPX_H
+#ifdef USE_UTMPX
static int check_login (const struct utmpx *ut)
-#else
+#else /* !USE_UTMPX */
static int check_login (const struct utmp *ut)
-#endif
+#endif /* !USE_UTMPX */
{
char user[sizeof (ut->ut_user) + 1];
time_t now;
strncpy (user, ut->ut_user, sizeof (ut->ut_user));
user[sizeof (ut->ut_user)] = '\0';
- time (&now);
+ (void) time (&now);
/*
* Check if they are allowed to be logged in right now.
{
TERMIO oldt, newt;
FILE *mesg_file, *tty_file;
- int c;
bool is_tty;
tty_file = fdopen (tty_fd, "w");
mesg_file = fopen (HUP_MESG_FILE, "r");
if (NULL != mesg_file) {
+ int c;
while ((c = getc (mesg_file)) != EOF) {
if (c == '\n') {
putc ('\r', tty_file);
int status;
pid_t pid;
-#if HAVE_UTMPX_H
+#ifdef USE_UTMPX
struct utmpx *ut;
-#else
+#else /* !USE_UTMPX */
struct utmp *ut;
-#endif
+#endif /* !USE_UTMPX */
char user[sizeof (ut->ut_user) + 1]; /* terminating NUL */
char tty_name[sizeof (ut->ut_line) + 6]; /* /dev/ + NUL */
int tty_fd;
+ if (1 != argc) {
+ (void) fputs (_("Usage: logoutd\n"), stderr);
+ }
+
(void) setlocale (LC_ALL, "");
(void) bindtextdomain (PACKAGE, LOCALEDIR);
(void) textdomain (PACKAGE);
pid = fork ();
if (pid > 0) {
/* parent */
- exit (0);
+ exit (EXIT_SUCCESS);
} else if (pid < 0) {
/* error */
perror ("fork");
- exit (1);
+ exit (EXIT_FAILURE);
}
#endif /* !DEBUG */
* Attempt to re-open the utmpx/utmp file. The file is only
* open while it is being used.
*/
-#if HAVE_UTMPX_H
+#ifdef USE_UTMPX
setutxent ();
-#else
+#else /* !USE_UTMPX */
setutent ();
-#endif
+#endif /* !USE_UTMPX */
/*
* Read all of the entries in the utmpx/utmp file. The entries
* for login sessions will be checked to see if the user
* is permitted to be signed on at this time.
*/
-#if HAVE_UTMPX_H
- while ((ut = getutxent ()) != NULL) {
-#else
- while ((ut = getutent ()) != NULL) {
-#endif
+#ifdef USE_UTMPX
+ while ((ut = getutxent ()) != NULL)
+#else /* !USE_UTMPX */
+ while ((ut = getutent ()) != NULL)
+#endif /* !USE_UTMPX */
+ {
if (ut->ut_type != USER_PROCESS) {
continue;
}
user[sizeof (user) - 1] = '\0';
SYSLOG ((LOG_NOTICE,
- "logged off user `%s' on `%s'", user,
+ "logged off user '%s' on '%s'", user,
tty_name));
/*
* This child has done all it can, drop dead.
*/
- exit (0);
+ exit (EXIT_SUCCESS);
}
-#if HAVE_UTMPX_H
+#ifdef USE_UTMPX
endutxent ();
-#else
+#else /* !USE_UTMPX */
endutent ();
-#endif
+#endif /* !USE_UTMPX */
#ifndef DEBUG
sleep (60);
*/
while (wait (&status) != -1);
}
- return 1;
- /* NOT REACHED */
+
+ return EXIT_FAILURE;
}