Gross Hack implementation base

This commit is contained in:
Misha
2021-12-09 22:22:17 -05:00
parent 6981e033be
commit c87dc3de93
3 changed files with 50 additions and 10 deletions

View File

@ -1,3 +1,4 @@
Daniel Drake <dsd@gentoo.org> Daniel Drake <dsd@gentoo.org>
Bastien Nocera <hadess@hadess.net> Bastien Nocera <hadess@hadess.net>
Misha <mishakmak@gmail.com>

11
README
View File

@ -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 fprintd
======= =======

View File

@ -18,8 +18,6 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include <config.h>
#define _GNU_SOURCE #define _GNU_SOURCE
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -30,6 +28,8 @@
#include <syslog.h> #include <syslog.h>
#include <errno.h> #include <errno.h>
#include <pthread.h>
#include <libintl.h> #include <libintl.h>
#include <systemd/sd-bus.h> #include <systemd/sd-bus.h>
#include <systemd/sd-login.h> #include <systemd/sd-login.h>
@ -194,6 +194,9 @@ typedef struct
pam_handle_t *pamh; pam_handle_t *pamh;
char *driver; char *driver;
sd_bus *bus;
bool stop_got_pw;
} verify_data; } verify_data;
static void static void
@ -296,8 +299,7 @@ verify_finger_selected (sd_bus_message *m,
} }
if (debug) if (debug)
pam_syslog (data->pamh, LOG_DEBUG, "verify_finger_selected %s", msg); 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; return 0;
} }
@ -383,9 +385,10 @@ typedef int fd_int;
PF_DEFINE_AUTO_CLEAN_FUNC (fd_int, fd_cleanup); PF_DEFINE_AUTO_CLEAN_FUNC (fd_int, fd_cleanup);
static int static int
do_verify (sd_bus *bus, do_verify (void *d)
verify_data *data)
{ {
verify_data *data = d;
sd_bus *bus = data->bus;
pf_autoptr (sd_bus_slot) verify_status_slot = NULL; pf_autoptr (sd_bus_slot) verify_status_slot = NULL;
pf_autoptr (sd_bus_slot) verify_finger_selected_slot = NULL; pf_autoptr (sd_bus_slot) verify_finger_selected_slot = NULL;
pf_autofree char *scan_type = NULL; pf_autofree char *scan_type = NULL;
@ -393,6 +396,8 @@ do_verify (sd_bus *bus,
fd_int signal_fd = -1; fd_int signal_fd = -1;
int r; int r;
data->stop_got_pw = false;
/* Get some properties for the device */ /* Get some properties for the device */
r = get_property_string (bus, r = get_property_string (bus,
"net.reactivated.Fprint", "net.reactivated.Fprint",
@ -483,7 +488,7 @@ do_verify (sd_bus *bus,
int64_t wait_time; int64_t wait_time;
wait_time = verification_end - now (); wait_time = verification_end - now ();
if (wait_time <= 0) if (data->stop_got_pw || wait_time <= 0)
break; break;
if (read (signal_fd, &siginfo, sizeof (siginfo)) > 0) if (read (signal_fd, &siginfo, sizeof (siginfo)) > 0)
@ -557,7 +562,7 @@ do_verify (sd_bus *bus,
NULL, NULL,
NULL); NULL);
if (data->timed_out) if (data->timed_out || data->stop_got_pw)
{ {
return PAM_AUTHINFO_UNAVAIL; return PAM_AUTHINFO_UNAVAIL;
} }
@ -710,6 +715,17 @@ name_owner_changed (sd_bus_message *m,
return 0; 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 static int
do_auth (pam_handle_t *pamh, const char *username) 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)) 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 */ /* Simply disconnect from bus if we return PAM_SUCCESS */
if (ret != PAM_SUCCESS) if (*ret != PAM_SUCCESS)
release_device (pamh, bus, data->dev); release_device (pamh, bus, data->dev);
sd_bus_close (bus); sd_bus_close (bus);