patch from tito: consolidate delay functions as bb_do_delay()
authorRob Landley <rob@landley.net>
Fri, 6 Jan 2006 20:59:09 +0000 (20:59 -0000)
committerRob Landley <rob@landley.net>
Fri, 6 Jan 2006 20:59:09 +0000 (20:59 -0000)
include/libbb.h
libbb/Makefile.in
libbb/bb_do_delay.c [new file with mode: 0644]
loginutils/login.c
loginutils/passwd.c
loginutils/sulogin.c
loginutils/vlock.c

index 52d91c8268d63766ad50d51880097f677c1a3125..f6efc40dff2facae18028f9dcbbb0b8f4d987085 100644 (file)
@@ -355,7 +355,7 @@ extern const char * const bb_default_login_shell;
 #define DEFAULT_SHELL_SHORT_NAME     (bb_default_login_shell+6)
 
 
-extern const char bb_path_mtab_file[];
+extern char bb_path_mtab_file[];
 
 extern int bb_default_error_retval;
 
@@ -419,6 +419,7 @@ extern size_t bb_strlen(const char *string);
 char *bb_xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
 
 #define FAIL_DELAY    3
+extern void bb_do_delay(int seconds);
 extern void change_identity ( const struct passwd *pw );
 extern const char *change_identity_e2str ( const struct passwd *pw );
 extern void run_shell ( const char *shell, int loginshell, const char *command, const char **additional_args);
index 35541231bc4c05cf031b837894841261ed9b7124..91698a919747b143dbb334ff07594d5f4d9f363d 100644 (file)
@@ -34,7 +34,7 @@ LIBBB_SRC-y:= \
        getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \
        perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \
        warn_ignoring_args.c concat_subpath_file.c vfork_daemon_rexec.c \
-       bb_echo.c
+       bb_echo.c bb_do_delay.c
 
 LIBBB_SRC-$(CONFIG_FEATURE_SHADOWPASSWDS)+= pwd2spwd.c
 
diff --git a/libbb/bb_do_delay.c b/libbb/bb_do_delay.c
new file mode 100644 (file)
index 0000000..ddcff07
--- /dev/null
@@ -0,0 +1,31 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Busybox utility routines.
+ *
+ * Copyright (C) 2005 by Tito Ragusa <tito-wolit@tiscali.it>
+ *
+ * Licensed under the GPL v2, see the file LICENSE in this tarball.
+ */
+
+#include <time.h>
+#include <unistd.h>
+
+void bb_do_delay(int seconds)
+{
+       time_t start, now;
+
+       time(&start);
+       now = start;
+       while (difftime(now, start) < seconds) {
+               sleep(seconds);
+               time(&now);
+       }
+}
+
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
index 6632a766508c31a604d065e6de62246a3bf109c9..21e807615ca3cbeae59d2db564a13a4d3f905167 100644 (file)
@@ -198,17 +198,7 @@ auth_ok:
                if ( !failed)
                        break;
 
-               { // delay next try
-                       time_t start, now;
-
-                       time ( &start );
-                       now = start;
-                       while ( difftime ( now, start ) < FAIL_DELAY) {
-                               sleep ( FAIL_DELAY );
-                               time ( &now );
-                       }
-               }
-
+               bb_do_delay(FAIL_DELAY);
                puts("Login incorrect");
                username[0] = 0;
                if ( ++count == 3 ) {
index 5d8380d4cbd92ccede3b93aeead21cb0515b5b02..b60b8973ec79c216fd71d72a21c2e9894d0fd51d 100644 (file)
@@ -323,7 +323,6 @@ static int new_password(const struct passwd *pw, int amroot, int algo)
        char *cp;
        char orig[200];
        char pass[200];
-       time_t start, now;
 
        if (!amroot && crypt_passwd[0]) {
                if (!(clear = bb_askpass(0, "Old password:"))) {
@@ -334,12 +333,7 @@ static int new_password(const struct passwd *pw, int amroot, int algo)
                if (strcmp(cipher, crypt_passwd) != 0) {
                        syslog(LOG_WARNING, "incorrect password for `%s'",
                                   pw->pw_name);
-                       time(&start);
-                       now = start;
-                       while (difftime(now, start) < FAIL_DELAY) {
-                               sleep(FAIL_DELAY);
-                               time(&now);
-                       }
+                       bb_do_delay(FAIL_DELAY);
                        fprintf(stderr, "Incorrect password.\n");
                        /* return -1; */
                        return 1;
index 4e689ad68ec0e456249d07a454a8d6c489dd0e1d..f54939eef9d9dd1728250d4fc934defdf1360f7f 100644 (file)
@@ -58,7 +58,6 @@ extern int sulogin_main(int argc, char **argv)
        
        struct passwd pwent;
        struct passwd *pwd;
-       time_t start, now;
        const char * const *p;
 #ifdef CONFIG_FEATURE_SHADOWPASSWDS
        struct spwd *spwd = NULL;
@@ -140,12 +139,7 @@ extern int sulogin_main(int argc, char **argv)
                if (strcmp(pw_encrypt(pass, pwent.pw_passwd), pwent.pw_passwd) == 0) {
                        break;
                }
-               time(&start);
-               now = start;
-               while (difftime(now, start) < FAIL_DELAY) {
-                       sleep(FAIL_DELAY);
-                       time(&now);
-               }
+               bb_do_delay(FAIL_DELAY);
                puts("Login incorrect");
                fflush(stdout);
                syslog(LOG_WARNING, "Incorrect root password\n");
index 141767c93fba83c166d8a3a57884ae22e3be2ec5..0975b515678770c8a5226c2f44bc0bb625ffd1ff 100644 (file)
@@ -135,7 +135,7 @@ extern int vlock_main(int argc, char **argv)
                if (correct_password (pw)) {
                        break;
                }
-               sleep(10);
+               bb_do_delay(FAIL_DELAY);
                puts("Password incorrect.");
        } while (1);
        restore_terminal();