mirror of
https://gitlab.com/mishakmak/pam-fprint-grosshack.git
synced 2026-04-09 04:13:33 +02:00
pam: don't use device name if there is only one reader
This commit is contained in:
committed by
Bastien Nocera
parent
77fa713920
commit
d77b59cd36
@ -22,23 +22,70 @@
|
|||||||
|
|
||||||
struct {
|
struct {
|
||||||
const char *dbus_name;
|
const char *dbus_name;
|
||||||
const char *place_str;
|
const char *place_str_generic;
|
||||||
const char *swipe_str;
|
const char *place_str_specific;
|
||||||
} fingers[11] = {
|
const char *swipe_str_generic;
|
||||||
{ "left-thumb", N_("Place your left thumb on %s"), N_("Swipe your left thumb on %s") },
|
const char *swipe_str_specific;
|
||||||
{ "left-index-finger", N_("Place your left index finger on %s"), N_("Swipe your left index finger on %s") },
|
} fingers[] = {
|
||||||
{ "left-middle-finger", N_("Place your left middle finger on %s"), N_("Swipe your left middle finger on %s") },
|
{ "any",
|
||||||
{ "left-ring-finger", N_("Place your left ring finger on %s"), N_("Swipe your left ring finger on %s") },
|
N_("Place your finger on the fingerprint reader"),
|
||||||
{ "left-little-finger", N_("Place your left little finger on %s"), N_("Swipe your left little finger on %s") },
|
N_("Place your finger on %s"),
|
||||||
{ "right-thumb", N_("Place your right thumb on %s"), N_("Swipe your right thumb on %s") },
|
N_("Swipe your finger across the fingerprint reader"),
|
||||||
{ "right-index-finger", N_("Place your right index finger on %s"), N_("Swipe your right index finger on %s") },
|
N_("Swipe your finger across %s") },
|
||||||
{ "right-middle-finger", N_("Place your right middle finger on %s"), N_("Swipe your right middle finger on %s") },
|
{ "left-thumb",
|
||||||
{ "right-ring-finger", N_("Place your right ring finger on %s"), N_("Swipe your right ring finger on %s") },
|
N_("Place your left thumb on the fingerprint reader"),
|
||||||
{ "right-little-finger", N_("Place your right little finger on %s"), N_("Swipe your right little finger on %s") },
|
N_("Place your left thumb on %s"),
|
||||||
{ NULL, NULL, NULL }
|
N_("Swipe your left thumb across the fingerprint reader"),
|
||||||
|
N_("Swipe your left thumb across %s") },
|
||||||
|
{ "left-index-finger",
|
||||||
|
N_("Place your left index finger on the fingerprint reader"),
|
||||||
|
N_("Place your left index finger on %s"),
|
||||||
|
N_("Swipe your left index finger across the fingerprint reader"),
|
||||||
|
N_("Swipe your left index finger across %s") },
|
||||||
|
{ "left-middle-finger",
|
||||||
|
N_("Place your left middle finger on the fingerprint reader"),
|
||||||
|
N_("Place your left middle finger on %s"),
|
||||||
|
N_("Swipe your left middle finger across the fingerprint reader"),
|
||||||
|
N_("Swipe your left middle finger across %s") },
|
||||||
|
{ "left-ring-finger",
|
||||||
|
N_("Place your left ring finger on the fingerprint reader"),
|
||||||
|
N_("Place your left ring finger on %s"),
|
||||||
|
N_("Swipe your left ring finger across the fingerprint reader"),
|
||||||
|
N_("Swipe your left ring finger across %s") },
|
||||||
|
{ "left-little-finger",
|
||||||
|
N_("Place your left little finger on the fingerprint reader"),
|
||||||
|
N_("Place your left little finger on %s"),
|
||||||
|
N_("Swipe your left little finger across the fingerprint reader"),
|
||||||
|
N_("Swipe your left little finger across %s") },
|
||||||
|
{ "right-thumb",
|
||||||
|
N_("Place your right thumb on the fingerprint reader"),
|
||||||
|
N_("Place your right thumb on %s"),
|
||||||
|
N_("Swipe your right thumb across the fingerprint reader"),
|
||||||
|
N_("Swipe your right thumb across %s") },
|
||||||
|
{ "right-index-finger",
|
||||||
|
N_("Place your right index finger on the fingerprint reader"),
|
||||||
|
N_("Place your right index finger on %s"),
|
||||||
|
N_("Swipe your right index finger across the fingerprint reader"),
|
||||||
|
N_("Swipe your right index finger across %s") },
|
||||||
|
{ "right-middle-finger",
|
||||||
|
N_("Place your right middle finger on the fingerprint reader"),
|
||||||
|
N_("Place your right middle finger on %s"),
|
||||||
|
N_("Swipe your right middle finger across the fingerprint reader"),
|
||||||
|
N_("Swipe your right middle finger across %s") },
|
||||||
|
{ "right-ring-finger",
|
||||||
|
N_("Place your right ring finger on the fingerprint reader"),
|
||||||
|
N_("Place your right ring finger on %s"),
|
||||||
|
N_("Swipe your right ring finger across the fingerprint reader"),
|
||||||
|
N_("Swipe your right ring finger across %s") },
|
||||||
|
{ "right-little-finger",
|
||||||
|
N_("Place your right little finger on the fingerprint reader"),
|
||||||
|
N_("Place your right little finger on %s"),
|
||||||
|
N_("Swipe your right little finger across the fingerprint reader"),
|
||||||
|
N_("Swipe your right little finger across %s") },
|
||||||
|
{ NULL, NULL, NULL, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *finger_str_to_msg(const char *finger_name, gboolean is_swipe)
|
static char *finger_str_to_msg(const char *finger_name, const char *driver_name, gboolean is_swipe)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -47,10 +94,17 @@ static const char *finger_str_to_msg(const char *finger_name, gboolean is_swipe)
|
|||||||
|
|
||||||
for (i = 0; fingers[i].dbus_name != NULL; i++) {
|
for (i = 0; fingers[i].dbus_name != NULL; i++) {
|
||||||
if (g_str_equal (fingers[i].dbus_name, finger_name)) {
|
if (g_str_equal (fingers[i].dbus_name, finger_name)) {
|
||||||
if (is_swipe == FALSE)
|
if (is_swipe == FALSE) {
|
||||||
return fingers[i].place_str;
|
if (driver_name)
|
||||||
|
return g_strdup_printf (TR (fingers[i].place_str_specific), driver_name);
|
||||||
else
|
else
|
||||||
return fingers[i].swipe_str;
|
return g_strdup (TR (fingers[i].place_str_generic));
|
||||||
|
} else {
|
||||||
|
if (driver_name)
|
||||||
|
return g_strdup_printf (TR (fingers[i].swipe_str_specific), driver_name);
|
||||||
|
else
|
||||||
|
return g_strdup (TR (fingers[i].swipe_str_generic));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -164,6 +164,29 @@ static void close_and_unref (DBusGConnection *connection)
|
|||||||
dbus_g_connection_unref (connection);
|
dbus_g_connection_unref (connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define DBUS_TYPE_G_OBJECT_PATH_ARRAY (dbus_g_type_get_collection ("GPtrArray", DBUS_TYPE_G_OBJECT_PATH))
|
||||||
|
|
||||||
|
static gboolean has_multiple_devices(pam_handle_t *pamh, DBusGProxy *manager)
|
||||||
|
{
|
||||||
|
GError *error = NULL;
|
||||||
|
GPtrArray *paths;
|
||||||
|
gboolean has_multiple;
|
||||||
|
|
||||||
|
if (!dbus_g_proxy_call (manager, "GetDevices", &error,
|
||||||
|
G_TYPE_INVALID, DBUS_TYPE_G_OBJECT_PATH_ARRAY,
|
||||||
|
&paths, G_TYPE_INVALID)) {
|
||||||
|
D(pamh, "get_devices failed: %s", error->message);
|
||||||
|
g_error_free (error);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
has_multiple = (paths->len > 1);
|
||||||
|
g_strfreev ((char **)paths->pdata);
|
||||||
|
g_ptr_array_free (paths, TRUE);
|
||||||
|
|
||||||
|
return has_multiple;
|
||||||
|
}
|
||||||
|
|
||||||
static DBusGProxy *open_device(pam_handle_t *pamh, DBusGConnection *connection, DBusGProxy *manager, const char *username)
|
static DBusGProxy *open_device(pam_handle_t *pamh, DBusGConnection *connection, DBusGProxy *manager, const char *username)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
@ -233,14 +256,8 @@ static void verify_finger_selected(GObject *object, const char *finger_name, gpo
|
|||||||
verify_data *data = user_data;
|
verify_data *data = user_data;
|
||||||
char *msg;
|
char *msg;
|
||||||
|
|
||||||
if (g_str_equal (finger_name, "any")) {
|
msg = finger_str_to_msg(finger_name, data->driver, data->is_swipe);
|
||||||
if (data->is_swipe == FALSE)
|
|
||||||
msg = g_strdup_printf ("Place your finger on %s", data->driver);
|
|
||||||
else
|
|
||||||
msg = g_strdup_printf ("Swipe your finger on %s", data->driver);
|
|
||||||
} else {
|
|
||||||
msg = g_strdup_printf (TR(finger_str_to_msg(finger_name, data->is_swipe)), data->driver);
|
|
||||||
}
|
|
||||||
D(data->pamh, "verify_finger_selected %s", msg);
|
D(data->pamh, "verify_finger_selected %s", msg);
|
||||||
send_info_msg (data->pamh, msg);
|
send_info_msg (data->pamh, msg);
|
||||||
g_free (msg);
|
g_free (msg);
|
||||||
@ -257,7 +274,7 @@ static gboolean verify_timeout_cb (gpointer user_data)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_verify(GMainLoop *loop, pam_handle_t *pamh, DBusGProxy *dev)
|
static int do_verify(GMainLoop *loop, pam_handle_t *pamh, DBusGProxy *dev, gboolean has_multiple_devices)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
GHashTable *props;
|
GHashTable *props;
|
||||||
@ -276,6 +293,7 @@ static int do_verify(GMainLoop *loop, pam_handle_t *pamh, DBusGProxy *dev)
|
|||||||
if (dbus_g_proxy_call (p, "GetAll", NULL, G_TYPE_STRING, "net.reactivated.Fprint.Device", G_TYPE_INVALID,
|
if (dbus_g_proxy_call (p, "GetAll", NULL, G_TYPE_STRING, "net.reactivated.Fprint.Device", G_TYPE_INVALID,
|
||||||
dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &props, G_TYPE_INVALID)) {
|
dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &props, G_TYPE_INVALID)) {
|
||||||
const char *scan_type;
|
const char *scan_type;
|
||||||
|
if (has_multiple_devices)
|
||||||
data->driver = g_value_dup_string (g_hash_table_lookup (props, "name"));
|
data->driver = g_value_dup_string (g_hash_table_lookup (props, "name"));
|
||||||
scan_type = g_value_dup_string (g_hash_table_lookup (props, "scan-type"));
|
scan_type = g_value_dup_string (g_hash_table_lookup (props, "scan-type"));
|
||||||
if (g_str_equal (scan_type, "swipe"))
|
if (g_str_equal (scan_type, "swipe"))
|
||||||
@ -285,9 +303,6 @@ static int do_verify(GMainLoop *loop, pam_handle_t *pamh, DBusGProxy *dev)
|
|||||||
|
|
||||||
g_object_unref (p);
|
g_object_unref (p);
|
||||||
|
|
||||||
if (!data->driver)
|
|
||||||
data->driver = g_strdup ("Fingerprint reader");
|
|
||||||
|
|
||||||
dbus_g_proxy_add_signal(dev, "VerifyStatus", G_TYPE_STRING, G_TYPE_BOOLEAN, NULL);
|
dbus_g_proxy_add_signal(dev, "VerifyStatus", G_TYPE_STRING, G_TYPE_BOOLEAN, NULL);
|
||||||
dbus_g_proxy_add_signal(dev, "VerifyFingerSelected", G_TYPE_STRING, NULL);
|
dbus_g_proxy_add_signal(dev, "VerifyFingerSelected", G_TYPE_STRING, NULL);
|
||||||
dbus_g_proxy_connect_signal(dev, "VerifyStatus", G_CALLBACK(verify_result),
|
dbus_g_proxy_connect_signal(dev, "VerifyStatus", G_CALLBACK(verify_result),
|
||||||
@ -388,7 +403,7 @@ static int do_auth(pam_handle_t *pamh, const char *username)
|
|||||||
close_and_unref (connection);
|
close_and_unref (connection);
|
||||||
return PAM_AUTHINFO_UNAVAIL;
|
return PAM_AUTHINFO_UNAVAIL;
|
||||||
}
|
}
|
||||||
ret = do_verify(loop, pamh, dev);
|
ret = do_verify(loop, pamh, dev, has_multiple_devices(pamh, manager));
|
||||||
|
|
||||||
g_main_loop_unref (loop);
|
g_main_loop_unref (loop);
|
||||||
release_device(pamh, dev);
|
release_device(pamh, dev);
|
||||||
|
|||||||
Reference in New Issue
Block a user