aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-01-06 20:59:09 +0000
committerlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-01-06 20:59:09 +0000
commit376cf8c4f05aba98dd98d82b8d5d1b6ca8a56b6a (patch)
treee9315133e3d21ea032e5e676ddb3f39e18be5605
parent129f57f04defd99cfb4b24fc15ce1456639daf1b (diff)
downloadbusybox-w32-376cf8c4f05aba98dd98d82b8d5d1b6ca8a56b6a.tar.gz
busybox-w32-376cf8c4f05aba98dd98d82b8d5d1b6ca8a56b6a.tar.bz2
busybox-w32-376cf8c4f05aba98dd98d82b8d5d1b6ca8a56b6a.zip
patch from tito: consolidate delay functions as bb_do_delay()
git-svn-id: svn://busybox.net/trunk/busybox@13135 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--include/libbb.h3
-rw-r--r--libbb/Makefile.in2
-rw-r--r--libbb/bb_do_delay.c31
-rw-r--r--loginutils/login.c12
-rw-r--r--loginutils/passwd.c8
-rw-r--r--loginutils/sulogin.c8
-rw-r--r--loginutils/vlock.c2
7 files changed, 38 insertions, 28 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 52d91c826..f6efc40df 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -355,7 +355,7 @@ extern const char * const bb_default_login_shell;
355#define DEFAULT_SHELL_SHORT_NAME (bb_default_login_shell+6) 355#define DEFAULT_SHELL_SHORT_NAME (bb_default_login_shell+6)
356 356
357 357
358extern const char bb_path_mtab_file[]; 358extern char bb_path_mtab_file[];
359 359
360extern int bb_default_error_retval; 360extern int bb_default_error_retval;
361 361
@@ -419,6 +419,7 @@ extern size_t bb_strlen(const char *string);
419char *bb_xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2))); 419char *bb_xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
420 420
421#define FAIL_DELAY 3 421#define FAIL_DELAY 3
422extern void bb_do_delay(int seconds);
422extern void change_identity ( const struct passwd *pw ); 423extern void change_identity ( const struct passwd *pw );
423extern const char *change_identity_e2str ( const struct passwd *pw ); 424extern const char *change_identity_e2str ( const struct passwd *pw );
424extern void run_shell ( const char *shell, int loginshell, const char *command, const char **additional_args); 425extern void run_shell ( const char *shell, int loginshell, const char *command, const char **additional_args);
diff --git a/libbb/Makefile.in b/libbb/Makefile.in
index 35541231b..91698a919 100644
--- a/libbb/Makefile.in
+++ b/libbb/Makefile.in
@@ -34,7 +34,7 @@ LIBBB_SRC-y:= \
34 getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \ 34 getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \
35 perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \ 35 perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \
36 warn_ignoring_args.c concat_subpath_file.c vfork_daemon_rexec.c \ 36 warn_ignoring_args.c concat_subpath_file.c vfork_daemon_rexec.c \
37 bb_echo.c 37 bb_echo.c bb_do_delay.c
38 38
39LIBBB_SRC-$(CONFIG_FEATURE_SHADOWPASSWDS)+= pwd2spwd.c 39LIBBB_SRC-$(CONFIG_FEATURE_SHADOWPASSWDS)+= pwd2spwd.c
40 40
diff --git a/libbb/bb_do_delay.c b/libbb/bb_do_delay.c
new file mode 100644
index 000000000..ddcff0765
--- /dev/null
+++ b/libbb/bb_do_delay.c
@@ -0,0 +1,31 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Busybox utility routines.
4 *
5 * Copyright (C) 2005 by Tito Ragusa <tito-wolit@tiscali.it>
6 *
7 * Licensed under the GPL v2, see the file LICENSE in this tarball.
8 */
9
10#include <time.h>
11#include <unistd.h>
12
13void bb_do_delay(int seconds)
14{
15 time_t start, now;
16
17 time(&start);
18 now = start;
19 while (difftime(now, start) < seconds) {
20 sleep(seconds);
21 time(&now);
22 }
23}
24
25/*
26Local Variables:
27c-file-style: "linux"
28c-basic-offset: 4
29tab-width: 4
30End:
31*/
diff --git a/loginutils/login.c b/loginutils/login.c
index 6632a7665..21e807615 100644
--- a/loginutils/login.c
+++ b/loginutils/login.c
@@ -198,17 +198,7 @@ auth_ok:
198 if ( !failed) 198 if ( !failed)
199 break; 199 break;
200 200
201 { // delay next try 201 bb_do_delay(FAIL_DELAY);
202 time_t start, now;
203
204 time ( &start );
205 now = start;
206 while ( difftime ( now, start ) < FAIL_DELAY) {
207 sleep ( FAIL_DELAY );
208 time ( &now );
209 }
210 }
211
212 puts("Login incorrect"); 202 puts("Login incorrect");
213 username[0] = 0; 203 username[0] = 0;
214 if ( ++count == 3 ) { 204 if ( ++count == 3 ) {
diff --git a/loginutils/passwd.c b/loginutils/passwd.c
index 5d8380d4c..b60b8973e 100644
--- a/loginutils/passwd.c
+++ b/loginutils/passwd.c
@@ -323,7 +323,6 @@ static int new_password(const struct passwd *pw, int amroot, int algo)
323 char *cp; 323 char *cp;
324 char orig[200]; 324 char orig[200];
325 char pass[200]; 325 char pass[200];
326 time_t start, now;
327 326
328 if (!amroot && crypt_passwd[0]) { 327 if (!amroot && crypt_passwd[0]) {
329 if (!(clear = bb_askpass(0, "Old password:"))) { 328 if (!(clear = bb_askpass(0, "Old password:"))) {
@@ -334,12 +333,7 @@ static int new_password(const struct passwd *pw, int amroot, int algo)
334 if (strcmp(cipher, crypt_passwd) != 0) { 333 if (strcmp(cipher, crypt_passwd) != 0) {
335 syslog(LOG_WARNING, "incorrect password for `%s'", 334 syslog(LOG_WARNING, "incorrect password for `%s'",
336 pw->pw_name); 335 pw->pw_name);
337 time(&start); 336 bb_do_delay(FAIL_DELAY);
338 now = start;
339 while (difftime(now, start) < FAIL_DELAY) {
340 sleep(FAIL_DELAY);
341 time(&now);
342 }
343 fprintf(stderr, "Incorrect password.\n"); 337 fprintf(stderr, "Incorrect password.\n");
344 /* return -1; */ 338 /* return -1; */
345 return 1; 339 return 1;
diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c
index 4e689ad68..f54939eef 100644
--- a/loginutils/sulogin.c
+++ b/loginutils/sulogin.c
@@ -58,7 +58,6 @@ extern int sulogin_main(int argc, char **argv)
58 58
59 struct passwd pwent; 59 struct passwd pwent;
60 struct passwd *pwd; 60 struct passwd *pwd;
61 time_t start, now;
62 const char * const *p; 61 const char * const *p;
63#ifdef CONFIG_FEATURE_SHADOWPASSWDS 62#ifdef CONFIG_FEATURE_SHADOWPASSWDS
64 struct spwd *spwd = NULL; 63 struct spwd *spwd = NULL;
@@ -140,12 +139,7 @@ extern int sulogin_main(int argc, char **argv)
140 if (strcmp(pw_encrypt(pass, pwent.pw_passwd), pwent.pw_passwd) == 0) { 139 if (strcmp(pw_encrypt(pass, pwent.pw_passwd), pwent.pw_passwd) == 0) {
141 break; 140 break;
142 } 141 }
143 time(&start); 142 bb_do_delay(FAIL_DELAY);
144 now = start;
145 while (difftime(now, start) < FAIL_DELAY) {
146 sleep(FAIL_DELAY);
147 time(&now);
148 }
149 puts("Login incorrect"); 143 puts("Login incorrect");
150 fflush(stdout); 144 fflush(stdout);
151 syslog(LOG_WARNING, "Incorrect root password\n"); 145 syslog(LOG_WARNING, "Incorrect root password\n");
diff --git a/loginutils/vlock.c b/loginutils/vlock.c
index 141767c93..0975b5156 100644
--- a/loginutils/vlock.c
+++ b/loginutils/vlock.c
@@ -135,7 +135,7 @@ extern int vlock_main(int argc, char **argv)
135 if (correct_password (pw)) { 135 if (correct_password (pw)) {
136 break; 136 break;
137 } 137 }
138 sleep(10); 138 bb_do_delay(FAIL_DELAY);
139 puts("Password incorrect."); 139 puts("Password incorrect.");
140 } while (1); 140 } while (1);
141 restore_terminal(); 141 restore_terminal();