aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2020-11-29 11:32:48 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2020-11-29 11:32:48 +0100
commit87bd558f3f0452ed62f2686472e03a1be4a6e36d (patch)
tree46fb42606d1d8ba65211e5e2f4261830a01b8c00
parent32a8f70ac1caa4037b63747c0c0a5086953ea668 (diff)
downloadbusybox-w32-87bd558f3f0452ed62f2686472e03a1be4a6e36d.tar.gz
busybox-w32-87bd558f3f0452ed62f2686472e03a1be4a6e36d.tar.bz2
busybox-w32-87bd558f3f0452ed62f2686472e03a1be4a6e36d.zip
libbb: bb_do_delay(3) -> pause_after_failed_login(), and stop looping there
function old new delta pause_after_failed_login - 9 +9 vlock_main 358 353 -5 sulogin_main 252 247 -5 su_main 484 479 -5 passwd_main 936 931 -5 login_main 967 962 -5 bb_do_delay 68 - -68 ------------------------------------------------------------------------------ (add/remove: 1/1 grow/shrink: 0/5 up/down: 9/-93) Total: -84 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/libbb.h7
-rw-r--r--libbb/bb_do_delay.c22
-rw-r--r--loginutils/login.c2
-rw-r--r--loginutils/passwd.c2
-rw-r--r--loginutils/su.c2
-rw-r--r--loginutils/sulogin.c2
-rw-r--r--loginutils/vlock.c2
-rw-r--r--networking/pscan.c2
8 files changed, 26 insertions, 15 deletions
diff --git a/include/libbb.h b/include/libbb.h
index e56fff3e8..6b822016e 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1604,9 +1604,10 @@ char *bb_simplify_abs_path_inplace(char *path) FAST_FUNC;
1604#ifndef LOGIN_FAIL_DELAY 1604#ifndef LOGIN_FAIL_DELAY
1605#define LOGIN_FAIL_DELAY 3 1605#define LOGIN_FAIL_DELAY 3
1606#endif 1606#endif
1607extern void bb_do_delay(int seconds) FAST_FUNC; 1607void pause_after_failed_login(void) FAST_FUNC;
1608extern void change_identity(const struct passwd *pw) FAST_FUNC; 1608void bb_do_delay(int seconds) FAST_FUNC;
1609extern void run_shell(const char *shell, int loginshell, const char **args) NORETURN FAST_FUNC; 1609void change_identity(const struct passwd *pw) FAST_FUNC;
1610void run_shell(const char *shell, int loginshell, const char **args) NORETURN FAST_FUNC;
1610 1611
1611/* Returns $SHELL, getpwuid(getuid())->pw_shell, or DEFAULT_SHELL. 1612/* Returns $SHELL, getpwuid(getuid())->pw_shell, or DEFAULT_SHELL.
1612 * Note that getpwuid result might need xstrdup'ing 1613 * Note that getpwuid result might need xstrdup'ing
diff --git a/libbb/bb_do_delay.c b/libbb/bb_do_delay.c
index 65541704b..29343305d 100644
--- a/libbb/bb_do_delay.c
+++ b/libbb/bb_do_delay.c
@@ -8,13 +8,23 @@
8 */ 8 */
9#include "libbb.h" 9#include "libbb.h"
10 10
11void FAST_FUNC bb_do_delay(int seconds) 11/* void FAST_FUNC bb_do_delay(int seconds) { ... } - no users yet */
12
13#ifndef LOGIN_FAIL_DELAY
14#define LOGIN_FAIL_DELAY 3
15#endif
16void FAST_FUNC pause_after_failed_login(void)
12{ 17{
13 time_t start, now; 18#if 0 /* over-engineered madness */
19 time_t end, diff;
14 20
15 start = time(NULL); 21 end = time(NULL) + LOGIN_FAIL_DELAY;
22 diff = LOGIN_FAIL_DELAY;
16 do { 23 do {
17 sleep(seconds); 24 sleep(diff);
18 now = time(NULL); 25 diff = end - time(NULL);
19 } while ((now - start) < seconds); 26 } while (diff > 0);
27#else
28 sleep(LOGIN_FAIL_DELAY);
29#endif
20} 30}
diff --git a/loginutils/login.c b/loginutils/login.c
index 3531d1424..c3a835180 100644
--- a/loginutils/login.c
+++ b/loginutils/login.c
@@ -505,7 +505,7 @@ int login_main(int argc UNUSED_PARAM, char **argv)
505#endif /* ENABLE_PAM */ 505#endif /* ENABLE_PAM */
506 auth_failed: 506 auth_failed:
507 opt &= ~LOGIN_OPT_f; 507 opt &= ~LOGIN_OPT_f;
508 bb_do_delay(LOGIN_FAIL_DELAY); 508 pause_after_failed_login();
509 /* TODO: doesn't sound like correct English phrase to me */ 509 /* TODO: doesn't sound like correct English phrase to me */
510 puts("Login incorrect"); 510 puts("Login incorrect");
511 if (++count == 3) { 511 if (++count == 3) {
diff --git a/loginutils/passwd.c b/loginutils/passwd.c
index 6c643d3d0..770acf58a 100644
--- a/loginutils/passwd.c
+++ b/loginutils/passwd.c
@@ -57,7 +57,7 @@ static char* new_password(const struct passwd *pw, uid_t myuid, const char *algo
57 encrypted = pw_encrypt(orig, pw->pw_passwd, 1); /* returns malloced str */ 57 encrypted = pw_encrypt(orig, pw->pw_passwd, 1); /* returns malloced str */
58 if (strcmp(encrypted, pw->pw_passwd) != 0) { 58 if (strcmp(encrypted, pw->pw_passwd) != 0) {
59 syslog(LOG_WARNING, "incorrect password for %s", pw->pw_name); 59 syslog(LOG_WARNING, "incorrect password for %s", pw->pw_name);
60 bb_do_delay(LOGIN_FAIL_DELAY); 60 pause_after_failed_login();
61 puts("Incorrect password"); 61 puts("Incorrect password");
62 goto err_ret; 62 goto err_ret;
63 } 63 }
diff --git a/loginutils/su.c b/loginutils/su.c
index 7c1fc69c5..6f91039f9 100644
--- a/loginutils/su.c
+++ b/loginutils/su.c
@@ -146,7 +146,7 @@ int su_main(int argc UNUSED_PARAM, char **argv)
146 if (ENABLE_FEATURE_SU_SYSLOG) 146 if (ENABLE_FEATURE_SU_SYSLOG)
147 syslog(LOG_NOTICE, "%c %s %s:%s", 147 syslog(LOG_NOTICE, "%c %s %s:%s",
148 '-', tty, old_user, opt_username); 148 '-', tty, old_user, opt_username);
149 bb_do_delay(LOGIN_FAIL_DELAY); 149 pause_after_failed_login();
150 bb_simple_error_msg_and_die("incorrect password"); 150 bb_simple_error_msg_and_die("incorrect password");
151 } 151 }
152 152
diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c
index 099085340..48dafd186 100644
--- a/loginutils/sulogin.c
+++ b/loginutils/sulogin.c
@@ -74,7 +74,7 @@ int sulogin_main(int argc UNUSED_PARAM, char **argv)
74 if (r > 0) { 74 if (r > 0) {
75 break; 75 break;
76 } 76 }
77 bb_do_delay(LOGIN_FAIL_DELAY); 77 pause_after_failed_login();
78 bb_simple_info_msg("Login incorrect"); 78 bb_simple_info_msg("Login incorrect");
79 } 79 }
80 80
diff --git a/loginutils/vlock.c b/loginutils/vlock.c
index 9e319fe61..334b7d2ad 100644
--- a/loginutils/vlock.c
+++ b/loginutils/vlock.c
@@ -120,7 +120,7 @@ int vlock_main(int argc UNUSED_PARAM, char **argv)
120 if (ask_and_check_password(pw) > 0) { 120 if (ask_and_check_password(pw) > 0) {
121 break; 121 break;
122 } 122 }
123 bb_do_delay(LOGIN_FAIL_DELAY); 123 pause_after_failed_login();
124 puts("Incorrect password"); 124 puts("Incorrect password");
125 } 125 }
126 126
diff --git a/networking/pscan.c b/networking/pscan.c
index 2715ef2df..e114e55d2 100644
--- a/networking/pscan.c
+++ b/networking/pscan.c
@@ -139,7 +139,7 @@ int pscan_main(int argc UNUSED_PARAM, char **argv)
139 * We check rtt BEFORE we usleep, otherwise 139 * We check rtt BEFORE we usleep, otherwise
140 * on localhost we'll have no writes done (!) 140 * on localhost we'll have no writes done (!)
141 * before we exceed (rather small) rtt */ 141 * before we exceed (rather small) rtt */
142 usleep(rtt_4/8); 142 usleep(rtt_4 / 8);
143 open: 143 open:
144 diff = MONOTONIC_US() - start; 144 diff = MONOTONIC_US() - start;
145 DMSG("write to port %u @%u", port, diff - start); 145 DMSG("write to port %u @%u", port, diff - start);