Authentication in multiple processes
Patch status: rejected
Patch by Philippe Virouleau
Long description:
Add the possibility to fork multiple times when submitting passwords. Fix #1090.
To apply this patch, use:
curl http://cr.i3wm.org/patch/283/raw.patch | git am
b/i3lock.c
15 |
@@ -45,6 +45,8 @@ static pam_handle_t *pam_handle; |
16 |
int input_position = 0; |
17 |
/* Holds the password you enter (in UTF-8). */ |
18 |
static char password[512]; |
19 |
+static int forked = 0; |
20 |
+static int max_forked = 4; |
21 |
static bool beep = false; |
22 |
bool debug_mode = false; |
23 |
static bool dpms = false; |
24 |
@@ -187,10 +189,14 @@ static void clear_pam_wrong(EV_P_ ev_timer *w, int revents) { |
25 |
clear_pam_wrong_timeout = NULL; |
26 |
} |
27 |
|
28 |
-static void clear_input(void) { |
29 |
+static void reset_input(void) { |
30 |
input_position = 0; |
31 |
clear_password_memory(); |
32 |
password[input_position] = '\0'; |
33 |
+} |
34 |
+ |
35 |
+static void clear_input(void) { |
36 |
+ reset_input(); |
37 |
|
38 |
/* Hide the unlock indicator after a bit if the password buffer is |
39 |
* empty. */ |
40 |
@@ -205,7 +211,6 @@ static void auth_failed(void) { |
41 |
fprintf(stderr, "Authentication failure\n"); |
42 |
|
43 |
pam_state = STATE_PAM_WRONG; |
44 |
- clear_input(); |
45 |
redraw_screen(); |
46 |
|
47 |
/* Clear this state after 2 seconds (unless the user enters another |
48 |
@@ -228,6 +233,7 @@ static void auth_failed(void) { |
49 |
} |
50 |
|
51 |
static void child_cb(EV_P_ ev_child *child_watcher, int revents) { |
52 |
+ forked--; |
53 |
if (child_watcher->rstatus != 0) { |
54 |
DEBUG("Authentication successfull\n"); |
55 |
clear_password_memory(); |
56 |
@@ -241,7 +247,9 @@ static void child_cb(EV_P_ ev_child *child_watcher, int revents) { |
57 |
} |
58 |
|
59 |
static void input_done(void) { |
60 |
- if (pam_state == STATE_PAM_VERIFY) { |
61 |
+ DEBUG("Forked : %i\n", forked); |
62 |
+ /*If there is too many fork then force the user to hit enter again*/ |
63 |
+ if (forked >= max_forked) { |
64 |
return; |
65 |
} |
66 |
|
67 |
@@ -259,6 +267,8 @@ static void input_done(void) { |
68 |
if (cpid == 0) { |
69 |
exit(pam_authenticate(pam_handle, 0) == PAM_SUCCESS); |
70 |
} else if (cpid > 0) { |
71 |
+ forked++; |
72 |
+ reset_input(); |
73 |
struct ev_child *child_watcher = calloc(sizeof(struct ev_io), 1); |
74 |
ev_child_init(child_watcher, child_cb, cpid, 0); |
75 |
ev_child_set(child_watcher, cpid, 0); |