]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
src/sulogin.c: Use a do-while loop
authorSamanta Navarro <ferivoz@riseup.net>
Fri, 19 Jan 2024 11:53:53 +0000 (11:53 +0000)
committerAlejandro Colomar <alx@kernel.org>
Thu, 1 Feb 2024 13:37:00 +0000 (14:37 +0100)
Clarify how this endless while(true) loop can be stopped by using a
boolean variable as condition and turn it into a do-while loop.

Suggested-by: Alejandro Colomar <alx@kernel.org>
Reviewed-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
src/sulogin.c

index 2ef00b6dfc78526f38a038f9d4deaf37da171ea9..440c7e0ce3fb702b45a2a772d862e063f05adc54 100644 (file)
@@ -64,6 +64,7 @@ main(int argc, char **argv)
        char           **envp = environ;
        TERMIO         termio;
        struct passwd  pwent = {};
+       bool           done;
 #ifndef USE_PAM
        const char     *env;
 #endif
@@ -133,7 +134,7 @@ main(int argc, char **argv)
        (void) signal (SIGALRM, catch_signals); /* exit if the timer expires */
        (void) alarm (ALARM);           /* only wait so long ... */
 
-       while (true) {          /* repeatedly get login/password pairs */
+       do {                    /* repeatedly get login/password pairs */
                char *cp;
                if (pw_entry("root", &pwent) == -1) {   /* get entry from password file */
                        /*
@@ -170,13 +171,13 @@ main(int argc, char **argv)
                STRTCPY(pass, cp);
                erase_pass (cp);
 
-               if (valid (pass, &pwent)) {     /* check encrypted passwords ... */
-                       break;  /* ... encrypted passwords matched */
+               done = valid(pass, &pwent);
+               if (!done) {    /* check encrypted passwords ... */
+                       /* ... encrypted passwords did not match */
+                       sleep (2);
+                       (void) puts (_("Login incorrect"));
                }
-
-               sleep (2);
-               (void) puts (_("Login incorrect"));
-       }
+       } while (!done);
        MEMZERO(pass);
        (void) alarm (0);
        (void) signal (SIGALRM, SIG_DFL);