From 101a14faf83e32869b92a314cb8f92c1ae59fe6d Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 17 Dec 2015 08:56:08 -0500 Subject: [swaylock] Stupid implementation of password entry --- swaylock/main.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'swaylock') 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 @@ #include "wayland-swaylock-client-protocol.h" +#include +#include #include #include #include #include +#include +#include #include "client/window.h" #include "client/registry.h" #include "client/cairo.h" @@ -30,6 +34,7 @@ void sway_terminate(void) { exit(EXIT_FAILURE); } +char *password; struct pam_response *pam_reply; 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, /** * password will be zeroed out. */ -bool verify_password(const char *username, char *password) { +bool verify_password(char *password) { + struct passwd *passwd = getpwuid(getuid()); + char *username = passwd->pw_name; + const struct pam_conv local_conversation = { function_conversation, NULL }; pam_handle_t *local_auth_handle = NULL; int pam_err; @@ -65,10 +73,29 @@ bool verify_password(const char *username, char *password) { void notify_key(enum wl_keyboard_key_state state, xkb_keysym_t sym, uint32_t code, uint32_t codepoint) { sway_log(L_INFO, "notified of key %c", (char)codepoint); + if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { + switch (sym) { + case XKB_KEY_Return: + if (verify_password(password)) { + exit(0); + } + break; + default: + { + int i = strlen(password); + password[i] = (char)codepoint; + password[i + 1] = '\0'; + sway_log(L_INFO, "pw: %s", password); + break; + } + } + } } int main(int argc, char **argv) { init_log(L_INFO); + password = malloc(1024); // TODO: Let this grow + password[0] = '\0'; surfaces = create_list(); registry = registry_poll(); -- cgit v1.2.3-54-g00ecf