]> granicus.if.org Git - shadow/blobdiff - src/logoutd.c
* src/grpconv.c: Fail if not called correctly.
[shadow] / src / logoutd.c
index e00af4b66daa874e0de919286a22ffa01a3506ce..1503a743ac61f49f8e16840256c126227986b40f 100644 (file)
@@ -43,7 +43,7 @@
 /*
  * Global variables
  */
-static char *Prog;
+const char *Prog;
 
 #ifndef DEFAULT_HUP_MESG
 #define DEFAULT_HUP_MESG _("login time exceeded\n\n")
@@ -53,20 +53,22 @@ static char *Prog;
 #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;
@@ -77,7 +79,7 @@ static int check_login (const struct utmp *ut)
        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.
@@ -93,7 +95,6 @@ static void send_mesg_to_tty (int tty_fd)
 {
        TERMIO oldt, newt;
        FILE *mesg_file, *tty_file;
-       int c;
        bool is_tty;
 
        tty_file = fdopen (tty_fd, "w");
@@ -112,6 +113,7 @@ static void send_mesg_to_tty (int tty_fd)
 
        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);
@@ -145,15 +147,19 @@ int main (int argc, char **argv)
        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);
@@ -169,11 +175,11 @@ int main (int argc, char **argv)
        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 */
 
@@ -194,22 +200,23 @@ int main (int argc, char **argv)
                 * 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;
                        }
@@ -263,20 +270,20 @@ int main (int argc, char **argv)
                        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);
@@ -286,7 +293,7 @@ int main (int argc, char **argv)
                 */
                while (wait (&status) != -1);
        }
-       return 1;
-       /* NOT REACHED */
+
+       return EXIT_FAILURE;
 }