From c87dc3de93dda38cb3834b02f9b087500744a33d Mon Sep 17 00:00:00 2001 From: Misha Date: Thu, 9 Dec 2021 22:22:17 -0500 Subject: [PATCH] Gross Hack implementation base --- AUTHORS | 1 + README | 11 +++++++++++ pam/pam_fprintd.c | 48 +++++++++++++++++++++++++++++++++++++---------- 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/AUTHORS b/AUTHORS index 935f5b4..22916c2 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,3 +1,4 @@ Daniel Drake Bastien Nocera +Misha diff --git a/README b/README index dd81c64..df493d3 100644 --- a/README +++ b/README @@ -1,3 +1,14 @@ +This is a fork of the pam module which implements the simultaneous +password and fingerprint behaviour present in pam_thinkfinger. It +was called a 'dirty hack' by the fprintd developers in the README +for the PAM module, but it works, and I am not beneath using it. + +-- Misha + +----------------------------------------------------------- +Original README +----------------------------------------------------------- + fprintd ======= diff --git a/pam/pam_fprintd.c b/pam/pam_fprintd.c index 8e1a17e..6bc4946 100644 --- a/pam/pam_fprintd.c +++ b/pam/pam_fprintd.c @@ -18,8 +18,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include - #define _GNU_SOURCE #include #include @@ -30,6 +28,8 @@ #include #include +#include + #include #include #include @@ -194,6 +194,9 @@ typedef struct pam_handle_t *pamh; char *driver; + + sd_bus *bus; + bool stop_got_pw; } verify_data; static void @@ -296,8 +299,7 @@ verify_finger_selected (sd_bus_message *m, } if (debug) pam_syslog (data->pamh, LOG_DEBUG, "verify_finger_selected %s", msg); - send_info_msg (data->pamh, msg); - + //send_info_msg (data->pamh, msg); return 0; } @@ -383,9 +385,10 @@ typedef int fd_int; PF_DEFINE_AUTO_CLEAN_FUNC (fd_int, fd_cleanup); static int -do_verify (sd_bus *bus, - verify_data *data) +do_verify (void *d) { + verify_data *data = d; + sd_bus *bus = data->bus; pf_autoptr (sd_bus_slot) verify_status_slot = NULL; pf_autoptr (sd_bus_slot) verify_finger_selected_slot = NULL; pf_autofree char *scan_type = NULL; @@ -393,6 +396,8 @@ do_verify (sd_bus *bus, fd_int signal_fd = -1; int r; + data->stop_got_pw = false; + /* Get some properties for the device */ r = get_property_string (bus, "net.reactivated.Fprint", @@ -483,7 +488,7 @@ do_verify (sd_bus *bus, int64_t wait_time; wait_time = verification_end - now (); - if (wait_time <= 0) + if (data->stop_got_pw || wait_time <= 0) break; if (read (signal_fd, &siginfo, sizeof (siginfo)) > 0) @@ -557,7 +562,7 @@ do_verify (sd_bus *bus, NULL, NULL); - if (data->timed_out) + if (data->timed_out || data->stop_got_pw) { return PAM_AUTHINFO_UNAVAIL; } @@ -710,6 +715,17 @@ name_owner_changed (sd_bus_message *m, return 0; } +static void +prompt_pw (void *d) +{ + verify_data *data = d; + char *pw; + pam_prompt (data->pamh, PAM_PROMPT_ECHO_OFF, &pw, "Enter Password or Place finger on fingerprint reader: "); + pam_set_item (data->pamh, PAM_AUTHTOK, pw); + data->stop_got_pw = true; + return; +} + static int do_auth (pam_handle_t *pamh, const char *username) { @@ -746,10 +762,22 @@ do_auth (pam_handle_t *pamh, const char *username) if (claim_device (pamh, bus, data->dev, username)) { - int ret = do_verify (bus, data); + data->bus = bus; + + pthread_t fprint_thread; + if (pthread_create (&fprint_thread, NULL, (void*) &do_verify, data) != 0) + send_err_msg (pamh, _("Failed to create thread")); + pthread_t pw_prompt_thread; + if (pthread_create (&pw_prompt_thread, NULL, (void*) &prompt_pw, data) != 0) + send_err_msg (pamh, _("Failed to create thread")); + + int *ret; + if (pthread_join (fprint_thread,(void**) &ret) != 0) + send_err_msg (pamh, _("Error joining with thread")); + pthread_cancel (pw_prompt_thread); /* Simply disconnect from bus if we return PAM_SUCCESS */ - if (ret != PAM_SUCCESS) + if (*ret != PAM_SUCCESS) release_device (pamh, bus, data->dev); sd_bus_close (bus);