diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-12-17 08:56:08 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-12-17 08:56:08 -0500 |
commit | 101a14faf83e32869b92a314cb8f92c1ae59fe6d (patch) | |
tree | 01d82e38cb37cb889cfa67a439efa04b306acb5d /swaylock | |
parent | Implement PAM password verification in swaylock (diff) | |
download | sway-101a14faf83e32869b92a314cb8f92c1ae59fe6d.tar.gz sway-101a14faf83e32869b92a314cb8f92c1ae59fe6d.tar.zst sway-101a14faf83e32869b92a314cb8f92c1ae59fe6d.zip |
[swaylock] Stupid implementation of password entry
Diffstat (limited to 'swaylock')
-rw-r--r-- | swaylock/main.c | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/swaylock/main.c b/swaylock/main.c index 19993ce6..c31a4552 100644 --- a/swaylock/main.c +++ b/swaylock/main.c | |||
@@ -1,8 +1,12 @@ | |||
1 | #include "wayland-swaylock-client-protocol.h" | 1 | #include "wayland-swaylock-client-protocol.h" |
2 | #include <xkbcommon/xkbcommon.h> | ||
3 | #include <xkbcommon/xkbcommon-names.h> | ||
2 | #include <security/pam_appl.h> | 4 | #include <security/pam_appl.h> |
3 | #include <stdio.h> | 5 | #include <stdio.h> |
4 | #include <stdlib.h> | 6 | #include <stdlib.h> |
5 | #include <string.h> | 7 | #include <string.h> |
8 | #include <sys/types.h> | ||
9 | #include <pwd.h> | ||
6 | #include "client/window.h" | 10 | #include "client/window.h" |
7 | #include "client/registry.h" | 11 | #include "client/registry.h" |
8 | #include "client/cairo.h" | 12 | #include "client/cairo.h" |
@@ -30,6 +34,7 @@ void sway_terminate(void) { | |||
30 | exit(EXIT_FAILURE); | 34 | exit(EXIT_FAILURE); |
31 | } | 35 | } |
32 | 36 | ||
37 | char *password; | ||
33 | struct pam_response *pam_reply; | 38 | struct pam_response *pam_reply; |
34 | 39 | ||
35 | int function_conversation(int num_msg, const struct pam_message **msg, | 40 | int function_conversation(int num_msg, const struct pam_message **msg, |
@@ -41,7 +46,10 @@ int function_conversation(int num_msg, const struct pam_message **msg, | |||
41 | /** | 46 | /** |
42 | * password will be zeroed out. | 47 | * password will be zeroed out. |
43 | */ | 48 | */ |
44 | bool verify_password(const char *username, char *password) { | 49 | bool verify_password(char *password) { |
50 | struct passwd *passwd = getpwuid(getuid()); | ||
51 | char *username = passwd->pw_name; | ||
52 | |||
45 | const struct pam_conv local_conversation = { function_conversation, NULL }; | 53 | const struct pam_conv local_conversation = { function_conversation, NULL }; |
46 | pam_handle_t *local_auth_handle = NULL; | 54 | pam_handle_t *local_auth_handle = NULL; |
47 | int pam_err; | 55 | int pam_err; |
@@ -65,10 +73,29 @@ bool verify_password(const char *username, char *password) { | |||
65 | 73 | ||
66 | void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t code, uint32_t codepoint) { | 74 | void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t code, uint32_t codepoint) { |
67 | sway_log(L_INFO, "notified of key %c", (char)codepoint); | 75 | sway_log(L_INFO, "notified of key %c", (char)codepoint); |
76 | if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { | ||
77 | switch (sym) { | ||
78 | case XKB_KEY_Return: | ||
79 | if (verify_password(password)) { | ||
80 | exit(0); | ||
81 | } | ||
82 | break; | ||
83 | default: | ||
84 | { | ||
85 | int i = strlen(password); | ||
86 | password[i] = (char)codepoint; | ||
87 | password[i + 1] = '\0'; | ||
88 | sway_log(L_INFO, "pw: %s", password); | ||
89 | break; | ||
90 | } | ||
91 | } | ||
92 | } | ||
68 | } | 93 | } |
69 | 94 | ||
70 | int main(int argc, char **argv) { | 95 | int main(int argc, char **argv) { |
71 | init_log(L_INFO); | 96 | init_log(L_INFO); |
97 | password = malloc(1024); // TODO: Let this grow | ||
98 | password[0] = '\0'; | ||
72 | surfaces = create_list(); | 99 | surfaces = create_list(); |
73 | registry = registry_poll(); | 100 | registry = registry_poll(); |
74 | 101 | ||