From: Samanta Navarro Date: Fri, 19 Jan 2024 11:53:53 +0000 (+0000) Subject: src/sulogin.c: Use a do-while loop X-Git-Tag: 4.15.0-rc1~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb42ee620e96cb158c715783ac7e2aca7983e0cb;p=thirdparty%2Fshadow.git src/sulogin.c: Use a do-while loop 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 Reviewed-by: Alejandro Colomar Signed-off-by: Samanta Navarro --- diff --git a/src/sulogin.c b/src/sulogin.c index 2ef00b6df..440c7e0ce 100644 --- a/src/sulogin.c +++ b/src/sulogin.c @@ -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);