diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | README.de.md | 2 | ||||
-rw-r--r-- | README.el.md | 2 | ||||
-rw-r--r-- | README.fr.md | 2 | ||||
-rw-r--r-- | README.it.md | 2 | ||||
-rw-r--r-- | README.ja.md | 2 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | README.pt.md | 2 | ||||
-rw-r--r-- | README.ru.md | 2 | ||||
-rw-r--r-- | README.uk.md | 2 | ||||
-rw-r--r-- | swaylock/main.c | 109 |
11 files changed, 64 insertions, 65 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index bd12b191..dc521570 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -59,7 +59,7 @@ if (LD_LIBRARY_PATH) | |||
59 | add_definitions(-D_LD_LIBRARY_PATH="${LD_LIBRARY_PATH}") | 59 | add_definitions(-D_LD_LIBRARY_PATH="${LD_LIBRARY_PATH}") |
60 | endif() | 60 | endif() |
61 | 61 | ||
62 | find_package(JsonC REQUIRED) | 62 | find_package(JsonC 0.12.1 REQUIRED) |
63 | find_package(PCRE REQUIRED) | 63 | find_package(PCRE REQUIRED) |
64 | find_package(WLC REQUIRED) | 64 | find_package(WLC REQUIRED) |
65 | find_package(Wayland REQUIRED) | 65 | find_package(Wayland REQUIRED) |
diff --git a/README.de.md b/README.de.md index 293ffe70..701cc34f 100644 --- a/README.de.md +++ b/README.de.md | |||
@@ -60,7 +60,7 @@ Abhängigkeiten: | |||
60 | * libcap | 60 | * libcap |
61 | * asciidoc | 61 | * asciidoc |
62 | * pcre | 62 | * pcre |
63 | * json-c | 63 | * json-c <= 0.12.1 |
64 | * pango | 64 | * pango |
65 | * cairo | 65 | * cairo |
66 | * gdk-pixbuf2 * | 66 | * gdk-pixbuf2 * |
diff --git a/README.el.md b/README.el.md index eba97b9c..df39364f 100644 --- a/README.el.md +++ b/README.el.md | |||
@@ -53,7 +53,7 @@ To username μου στο Freenode είναι kon14 και θα με βρείτ | |||
53 | * libcap | 53 | * libcap |
54 | * asciidoc | 54 | * asciidoc |
55 | * pcre | 55 | * pcre |
56 | * json-c | 56 | * json-c <= 0.12.1 |
57 | * pango | 57 | * pango |
58 | * cairo | 58 | * cairo |
59 | * gdk-pixbuf2 * | 59 | * gdk-pixbuf2 * |
diff --git a/README.fr.md b/README.fr.md index a4ff7cb9..47b6c410 100644 --- a/README.fr.md +++ b/README.fr.md | |||
@@ -55,7 +55,7 @@ Installez les dépendances : | |||
55 | * libcap | 55 | * libcap |
56 | * asciidoc | 56 | * asciidoc |
57 | * pcre | 57 | * pcre |
58 | * json-c | 58 | * json-c <= 0.12.1 |
59 | * pango | 59 | * pango |
60 | * cairo | 60 | * cairo |
61 | * gdk-pixbuf2 * | 61 | * gdk-pixbuf2 * |
diff --git a/README.it.md b/README.it.md index ded441c3..f5e0d8e2 100644 --- a/README.it.md +++ b/README.it.md | |||
@@ -56,7 +56,7 @@ Installa queste dipendenze: | |||
56 | * libcap | 56 | * libcap |
57 | * asciidoc | 57 | * asciidoc |
58 | * pcre | 58 | * pcre |
59 | * json-c | 59 | * json-c <= 0.12.1 |
60 | * pango | 60 | * pango |
61 | * cairo | 61 | * cairo |
62 | * gdk-pixbuf2 * | 62 | * gdk-pixbuf2 * |
diff --git a/README.ja.md b/README.ja.md index 94b4ce9d..2e8f9bfb 100644 --- a/README.ja.md +++ b/README.ja.md | |||
@@ -46,7 +46,7 @@ Swayは沢山のディストリビューションで提供されています。" | |||
46 | * libcap | 46 | * libcap |
47 | * asciidoc | 47 | * asciidoc |
48 | * pcre | 48 | * pcre |
49 | * json-c | 49 | * json-c <= 0.12.1 |
50 | * pango | 50 | * pango |
51 | * cairo | 51 | * cairo |
52 | * gdk-pixbuf2 * | 52 | * gdk-pixbuf2 * |
@@ -61,7 +61,7 @@ Install dependencies: | |||
61 | * libcap | 61 | * libcap |
62 | * asciidoc | 62 | * asciidoc |
63 | * pcre | 63 | * pcre |
64 | * json-c | 64 | * json-c <= 0.12.1 |
65 | * pango | 65 | * pango |
66 | * cairo | 66 | * cairo |
67 | * gdk-pixbuf2 * | 67 | * gdk-pixbuf2 * |
diff --git a/README.pt.md b/README.pt.md index e35849ec..b5ca132f 100644 --- a/README.pt.md +++ b/README.pt.md | |||
@@ -62,7 +62,7 @@ Antes de iniciar a compilação, instale as dependências: | |||
62 | * libcap | 62 | * libcap |
63 | * asciidoc | 63 | * asciidoc |
64 | * pcre | 64 | * pcre |
65 | * json-c | 65 | * json-c <= 0.12.1 |
66 | * pango | 66 | * pango |
67 | * cairo | 67 | * cairo |
68 | * gdk-pixbuf2 * | 68 | * gdk-pixbuf2 * |
diff --git a/README.ru.md b/README.ru.md index 1551caa0..4035b0fc 100644 --- a/README.ru.md +++ b/README.ru.md | |||
@@ -55,7 +55,7 @@ Sway доступен во многих дистрибутивах и наход | |||
55 | * libcap | 55 | * libcap |
56 | * asciidoc | 56 | * asciidoc |
57 | * pcre | 57 | * pcre |
58 | * json-c | 58 | * json-c <= 0.12.1 |
59 | * pango | 59 | * pango |
60 | * cairo | 60 | * cairo |
61 | * gdk-pixbuf2 * | 61 | * gdk-pixbuf2 * |
diff --git a/README.uk.md b/README.uk.md index c8520e4b..2e107afc 100644 --- a/README.uk.md +++ b/README.uk.md | |||
@@ -62,7 +62,7 @@ Sway доступний у багатьох дистрибутивах Linux (а | |||
62 | * libcap | 62 | * libcap |
63 | * asciidoc | 63 | * asciidoc |
64 | * pcre | 64 | * pcre |
65 | * json-c | 65 | * json-c <= 0.12.1 |
66 | * pango | 66 | * pango |
67 | * cairo | 67 | * cairo |
68 | * gdk-pixbuf2 * | 68 | * gdk-pixbuf2 * |
diff --git a/swaylock/main.c b/swaylock/main.c index 7b7dd601..3208a45b 100644 --- a/swaylock/main.c +++ b/swaylock/main.c | |||
@@ -6,6 +6,7 @@ | |||
6 | #include <stdio.h> | 6 | #include <stdio.h> |
7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
8 | #include <string.h> | 8 | #include <string.h> |
9 | #include <sys/mman.h> | ||
9 | #include <sys/types.h> | 10 | #include <sys/types.h> |
10 | #include <pwd.h> | 11 | #include <pwd.h> |
11 | #include <getopt.h> | 12 | #include <getopt.h> |
@@ -56,8 +57,7 @@ void sway_terminate(int exit_code) { | |||
56 | exit(exit_code); | 57 | exit(exit_code); |
57 | } | 58 | } |
58 | 59 | ||
59 | char *password; | 60 | char password[1024]; |
60 | int password_size; | ||
61 | enum line_source line_source = LINE_SOURCE_DEFAULT; | 61 | enum line_source line_source = LINE_SOURCE_DEFAULT; |
62 | 62 | ||
63 | struct lock_config *init_config() { | 63 | struct lock_config *init_config() { |
@@ -115,7 +115,7 @@ int function_conversation(int num_msg, const struct pam_message **msg, | |||
115 | switch (msg[i]->msg_style) { | 115 | switch (msg[i]->msg_style) { |
116 | case PAM_PROMPT_ECHO_OFF: | 116 | case PAM_PROMPT_ECHO_OFF: |
117 | case PAM_PROMPT_ECHO_ON: | 117 | case PAM_PROMPT_ECHO_ON: |
118 | pam_reply[i].resp = password; | 118 | pam_reply[i].resp = strdup(password); // PAM clears and frees this |
119 | break; | 119 | break; |
120 | 120 | ||
121 | case PAM_ERROR_MSG: | 121 | case PAM_ERROR_MSG: |
@@ -127,9 +127,15 @@ int function_conversation(int num_msg, const struct pam_message **msg, | |||
127 | return PAM_SUCCESS; | 127 | return PAM_SUCCESS; |
128 | } | 128 | } |
129 | 129 | ||
130 | /** | 130 | void clear_password_buffer() { |
131 | * Note: PAM will free() 'password' during the process | 131 | // Use volatile keyword so so compiler can't optimize this out. |
132 | */ | 132 | volatile char *pw = password; |
133 | volatile char zero = '\0'; | ||
134 | for (size_t i = 0; i < sizeof(password); ++i) { | ||
135 | pw[i] = zero; | ||
136 | } | ||
137 | } | ||
138 | |||
133 | bool verify_password() { | 139 | bool verify_password() { |
134 | struct passwd *passwd = getpwuid(getuid()); | 140 | struct passwd *passwd = getpwuid(getuid()); |
135 | char *username = passwd->pw_name; | 141 | char *username = passwd->pw_name; |
@@ -151,8 +157,7 @@ bool verify_password() { | |||
151 | 157 | ||
152 | void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t code, uint32_t codepoint) { | 158 | void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t code, uint32_t codepoint) { |
153 | int redraw_screen = 0; | 159 | int redraw_screen = 0; |
154 | char *password_realloc; | 160 | size_t i; |
155 | int i; | ||
156 | 161 | ||
157 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { | 162 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { |
158 | switch (sym) { | 163 | switch (sym) { |
@@ -165,14 +170,14 @@ void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t cod | |||
165 | wl_dispatch_events(); | 170 | wl_dispatch_events(); |
166 | 171 | ||
167 | if (verify_password()) { | 172 | if (verify_password()) { |
173 | clear_password_buffer(); | ||
168 | exit(0); | 174 | exit(0); |
169 | } | 175 | } |
170 | 176 | ||
171 | render_data.auth_state = AUTH_STATE_INVALID; | 177 | render_data.auth_state = AUTH_STATE_INVALID; |
172 | redraw_screen = 1; | 178 | redraw_screen = 1; |
173 | 179 | ||
174 | password_size = 1024; | 180 | clear_password_buffer(); |
175 | password = malloc(password_size); | ||
176 | password[0] = '\0'; | 181 | password[0] = '\0'; |
177 | break; | 182 | break; |
178 | case XKB_KEY_BackSpace: | 183 | case XKB_KEY_BackSpace: |
@@ -207,9 +212,7 @@ void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t cod | |||
207 | render_data.auth_state = AUTH_STATE_BACKSPACE; | 212 | render_data.auth_state = AUTH_STATE_BACKSPACE; |
208 | redraw_screen = 1; | 213 | redraw_screen = 1; |
209 | 214 | ||
210 | password_size = 1024; | 215 | clear_password_buffer(); |
211 | free(password); | ||
212 | password = malloc(password_size); | ||
213 | password[0] = '\0'; | 216 | password[0] = '\0'; |
214 | break; | 217 | break; |
215 | } | 218 | } |
@@ -218,22 +221,10 @@ void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t cod | |||
218 | render_data.auth_state = AUTH_STATE_INPUT; | 221 | render_data.auth_state = AUTH_STATE_INPUT; |
219 | redraw_screen = 1; | 222 | redraw_screen = 1; |
220 | i = strlen(password); | 223 | i = strlen(password); |
221 | if (i + 1 == password_size) { | 224 | if (i + 1 < sizeof(password)) { |
222 | password_size += 1024; | 225 | password[i] = (char)codepoint; |
223 | password_realloc = realloc(password, password_size); | 226 | password[i + 1] = '\0'; |
224 | // reset password if realloc fails. | ||
225 | if (password_realloc == NULL) { | ||
226 | password_size = 1024; | ||
227 | free(password); | ||
228 | password = malloc(password_size); | ||
229 | password[0] = '\0'; | ||
230 | break; | ||
231 | } else { | ||
232 | password = password_realloc; | ||
233 | } | ||
234 | } | 227 | } |
235 | password[i] = (char)codepoint; | ||
236 | password[i + 1] = '\0'; | ||
237 | break; | 228 | break; |
238 | } | 229 | } |
239 | if (redraw_screen) { | 230 | if (redraw_screen) { |
@@ -343,6 +334,7 @@ cairo_surface_t *load_image(char *image_path) { | |||
343 | 334 | ||
344 | int main(int argc, char **argv) { | 335 | int main(int argc, char **argv) { |
345 | const char *scaling_mode_str = "fit", *socket_path = NULL; | 336 | const char *scaling_mode_str = "fit", *socket_path = NULL; |
337 | char *image_path = NULL; | ||
346 | int i; | 338 | int i; |
347 | void *images = NULL; | 339 | void *images = NULL; |
348 | config = init_config(); | 340 | config = init_config(); |
@@ -400,8 +392,6 @@ int main(int argc, char **argv) { | |||
400 | " For more information see `man swaylock`\n"; | 392 | " For more information see `man swaylock`\n"; |
401 | 393 | ||
402 | 394 | ||
403 | registry = registry_poll(); | ||
404 | |||
405 | int c; | 395 | int c; |
406 | while (1) { | 396 | while (1) { |
407 | int option_index = 0; | 397 | int option_index = 0; |
@@ -418,29 +408,7 @@ int main(int argc, char **argv) { | |||
418 | } | 408 | } |
419 | case 'i': | 409 | case 'i': |
420 | { | 410 | { |
421 | char *image_path = strchr(optarg, ':'); | 411 | image_path = optarg; |
422 | if (image_path == NULL) { | ||
423 | if (render_data.num_images == 0) { | ||
424 | // Provided image without output | ||
425 | render_data.image = load_image(optarg); | ||
426 | render_data.num_images = -1; | ||
427 | } else { | ||
428 | sway_log(L_ERROR, "output must be defined for all --images or no --images"); | ||
429 | exit(EXIT_FAILURE); | ||
430 | } | ||
431 | } else { | ||
432 | // Provided image for all outputs | ||
433 | if (render_data.num_images == 0) { | ||
434 | images = calloc(registry->outputs->length, sizeof(char*) * 2); | ||
435 | } else if (render_data.num_images == -1) { | ||
436 | sway_log(L_ERROR, "output must be defined for all --images or no --images"); | ||
437 | exit(EXIT_FAILURE); | ||
438 | } | ||
439 | |||
440 | image_path[0] = '\0'; | ||
441 | ((char**) images)[render_data.num_images * 2] = optarg; | ||
442 | ((char**) images)[render_data.num_images++ * 2 + 1] = ++image_path; | ||
443 | } | ||
444 | break; | 412 | break; |
445 | } | 413 | } |
446 | case 't': | 414 | case 't': |
@@ -519,6 +487,33 @@ int main(int argc, char **argv) { | |||
519 | exit(EXIT_FAILURE); | 487 | exit(EXIT_FAILURE); |
520 | } | 488 | } |
521 | } | 489 | } |
490 | registry = registry_poll(); | ||
491 | |||
492 | if (image_path) { | ||
493 | char *path = strchr(image_path, ':'); | ||
494 | if (path == NULL) { | ||
495 | if (render_data.num_images == 0) { | ||
496 | // Provided image without output | ||
497 | render_data.image = load_image(image_path); | ||
498 | render_data.num_images = -1; | ||
499 | } else { | ||
500 | sway_log(L_ERROR, "output must be defined for all --images or no --images"); | ||
501 | exit(EXIT_FAILURE); | ||
502 | } | ||
503 | } else { | ||
504 | // Provided image for all outputs | ||
505 | if (render_data.num_images == 0) { | ||
506 | images = calloc(registry->outputs->length, sizeof(char*) * 2); | ||
507 | } else if (render_data.num_images == -1) { | ||
508 | sway_log(L_ERROR, "output must be defined for all --images or no --images"); | ||
509 | exit(EXIT_FAILURE); | ||
510 | } | ||
511 | |||
512 | path[0] = '\0'; | ||
513 | ((char**) images)[render_data.num_images * 2] = image_path; | ||
514 | ((char**) images)[render_data.num_images++ * 2 + 1] = ++path; | ||
515 | } | ||
516 | } | ||
522 | 517 | ||
523 | render_data.scaling_mode = SCALING_MODE_STRETCH; | 518 | render_data.scaling_mode = SCALING_MODE_STRETCH; |
524 | if (strcmp(scaling_mode_str, "stretch") == 0) { | 519 | if (strcmp(scaling_mode_str, "stretch") == 0) { |
@@ -535,8 +530,12 @@ int main(int argc, char **argv) { | |||
535 | sway_abort("Unsupported scaling mode: %s", scaling_mode_str); | 530 | sway_abort("Unsupported scaling mode: %s", scaling_mode_str); |
536 | } | 531 | } |
537 | 532 | ||
538 | password_size = 1024; | 533 | #ifdef __linux__ |
539 | password = malloc(password_size); | 534 | // Most non-linux platforms require root to mlock() |
535 | if (mlock(password, sizeof(password)) != 0) { | ||
536 | sway_abort("Unable to mlock() password memory."); | ||
537 | } | ||
538 | #endif | ||
540 | password[0] = '\0'; | 539 | password[0] = '\0'; |
541 | render_data.surfaces = create_list(); | 540 | render_data.surfaces = create_list(); |
542 | if (!socket_path) { | 541 | if (!socket_path) { |