Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1 | Upstream-Status: Pending |
| 2 | |
| 3 | written by: Jeff Polk <jeff.polk@windriver.com> |
| 4 | Signed-off-by: Jackie Huang <jackie.huang@windriver.com> |
| 5 | |
| 6 | --- a/Makefile |
| 7 | +++ b/Makefile |
| 8 | @@ -126,6 +126,10 @@ ifeq ($(AUTH_METHOD),shadow) |
| 9 | vlock-main : override LDLIBS += $(CRYPT_LIB) |
| 10 | endif |
| 11 | |
| 12 | +ifneq ($(ENABLE_FAIL_COUNT),yes) |
| 13 | +vlock-main.o : override CFLAGS += -DNO_FAIL_COUNT |
| 14 | +endif |
| 15 | + |
| 16 | ifeq ($(ENABLE_PLUGINS),yes) |
| 17 | vlock-main: plugins.o plugin.o module.o process.o script.o tsort.o list.o |
| 18 | # -rdynamic is needed so that the all plugin can access the symbols from console_switch.o |
| 19 | --- a/configure |
| 20 | +++ b/configure |
| 21 | @@ -44,6 +44,7 @@ Optional Features: |
| 22 | --enable-shadow enable shadow authentication [disabled] |
| 23 | --enable-root-password enable unlogging with root password [enabled] |
| 24 | --enable-debug enable debugging |
| 25 | + --enable-fail-count enable failed login attempt summary [enabled] |
| 26 | |
| 27 | Additional configuration: |
| 28 | --with-scripts=SCRIPTS enable the named scripts [] |
| 29 | @@ -78,6 +79,9 @@ enable_feature() { |
| 30 | root-password) |
| 31 | ENABLE_ROOT_PASSWORD="$2" |
| 32 | ;; |
| 33 | + fail-count) |
| 34 | + ENABLE_FAIL_COUNT="$2" |
| 35 | + ;; |
| 36 | pam|shadow) |
| 37 | if [ "$2" = "yes" ] ; then |
| 38 | if [ -n "$auth_method" ] && [ "$auth_method" != "$1" ] ; then |
| 39 | @@ -232,6 +232,7 @@ set_defaults() { |
| 40 | AUTH_METHOD="pam" |
| 41 | ENABLE_ROOT_PASSWORD="yes" |
| 42 | ENABLE_PLUGINS="yes" |
| 43 | + ENABLE_FAIL_COUNT="yes" |
| 44 | SCRIPTS="" |
| 45 | |
| 46 | VLOCK_GROUP="vlock" |
| 47 | @@ -356,10 +356,14 @@ ENABLE_PLUGINS = ${ENABLE_PLUGINS} |
| 48 | # which plugins should be build |
| 49 | MODULES = ${MODULES} |
| 50 | # which scripts should be installed |
| 51 | SCRIPTS = ${SCRIPTS} |
| 52 | |
| 53 | +# display a summary of failed authentication attempts after successfully |
| 54 | +# unlocking? |
| 55 | +ENABLE_FAIL_COUNT = ${ENABLE_FAIL_COUNT} |
| 56 | + |
| 57 | # root's group |
| 58 | ROOT_GROUP = ${ROOT_GROUP} |
| 59 | |
| 60 | # group for privileged plugins |
| 61 | VLOCK_GROUP = ${VLOCK_GROUP} |
| 62 | --- a/src/vlock-main.c |
| 63 | +++ b/src/vlock-main.c |
| 64 | @@ -111,7 +111,9 @@ static void restore_terminal(void) |
| 65 | (void) tcsetattr(STDIN_FILENO, TCSANOW, &term); |
| 66 | } |
| 67 | |
| 68 | +#ifdef ENABLE_FAIL_COUNT |
| 69 | static int auth_tries; |
| 70 | +#endif /* ENABLE_FAIL_COUNT */ |
| 71 | |
| 72 | static void auth_loop(const char *username) |
| 73 | { |
| 74 | @@ -181,7 +183,9 @@ static void auth_loop(const char *userna |
| 75 | } |
| 76 | #endif |
| 77 | |
| 78 | +#ifdef ENABLE_FAIL_COUNT |
| 79 | auth_tries++; |
| 80 | +#endif /* ENABLE_FAIL_COUNT */ |
| 81 | } |
| 82 | |
| 83 | /* Free timeouts memory. */ |
| 84 | @@ -189,11 +193,13 @@ static void auth_loop(const char *userna |
| 85 | free(prompt_timeout); |
| 86 | } |
| 87 | |
| 88 | +#ifdef ENABLE_FAIL_COUNT |
| 89 | void display_auth_tries(void) |
| 90 | { |
| 91 | if (auth_tries > 0) |
| 92 | fprintf(stderr, "%d failed authentication %s.\n", auth_tries, auth_tries > 1 ? "tries" : "try"); |
| 93 | } |
| 94 | +#endif /* ENABLE_FAIL_COUNT */ |
| 95 | |
| 96 | #ifdef USE_PLUGINS |
| 97 | static void call_end_hook(void) |
| 98 | @@ -216,7 +222,9 @@ int main(int argc, char *const argv[]) |
| 99 | if (username == NULL) |
| 100 | fatal_perror("vlock: could not get username"); |
| 101 | |
| 102 | +#ifdef ENABLE_FAIL_COUNT |
| 103 | ensure_atexit(display_auth_tries); |
| 104 | +#endif /* ENABLE_FAIL_COUNT */ |
| 105 | |
| 106 | #ifdef USE_PLUGINS |
| 107 | for (int i = 1; i < argc; i++) |