Commit d77b59cd authored by Dan Winship's avatar Dan Winship Committed by Bastien Nocera

pam: don't use device name if there is only one reader

parent 77fa7139
......@@ -22,23 +22,70 @@
struct {
const char *dbus_name;
const char *place_str;
const char *swipe_str;
} fingers[11] = {
{ "left-thumb", N_("Place your left thumb on %s"), N_("Swipe your left thumb on %s") },
{ "left-index-finger", N_("Place your left index finger on %s"), N_("Swipe your left index finger on %s") },
{ "left-middle-finger", N_("Place your left middle finger on %s"), N_("Swipe your left middle finger on %s") },
{ "left-ring-finger", N_("Place your left ring finger on %s"), N_("Swipe your left ring finger on %s") },
{ "left-little-finger", N_("Place your left little finger on %s"), N_("Swipe your left little finger on %s") },
{ "right-thumb", N_("Place your right thumb on %s"), N_("Swipe your right thumb on %s") },
{ "right-index-finger", N_("Place your right index finger on %s"), N_("Swipe your right index finger on %s") },
{ "right-middle-finger", N_("Place your right middle finger on %s"), N_("Swipe your right middle finger on %s") },
{ "right-ring-finger", N_("Place your right ring finger on %s"), N_("Swipe your right ring finger on %s") },
{ "right-little-finger", N_("Place your right little finger on %s"), N_("Swipe your right little finger on %s") },
{ NULL, NULL, NULL }
const char *place_str_generic;
const char *place_str_specific;
const char *swipe_str_generic;
const char *swipe_str_specific;
} fingers[] = {
{ "any",
N_("Place your finger on the fingerprint reader"),
N_("Place your finger on %s"),
N_("Swipe your finger across the fingerprint reader"),
N_("Swipe your finger across %s") },
{ "left-thumb",
N_("Place your left thumb on the fingerprint reader"),
N_("Place your left thumb on %s"),
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;
......@@ -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++) {
if (g_str_equal (fingers[i].dbus_name, finger_name)) {
if (is_swipe == FALSE)
return fingers[i].place_str;
else
return fingers[i].swipe_str;
if (is_swipe == FALSE) {
if (driver_name)
return g_strdup_printf (TR (fingers[i].place_str_specific), driver_name);
else
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);
}
#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)
{
GError *error = NULL;
......@@ -233,14 +256,8 @@ static void verify_finger_selected(GObject *object, const char *finger_name, gpo
verify_data *data = user_data;
char *msg;
if (g_str_equal (finger_name, "any")) {
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);
}
msg = finger_str_to_msg(finger_name, data->driver, data->is_swipe);
D(data->pamh, "verify_finger_selected %s", msg);
send_info_msg (data->pamh, msg);
g_free (msg);
......@@ -257,7 +274,7 @@ static gboolean verify_timeout_cb (gpointer user_data)
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;
GHashTable *props;
......@@ -276,7 +293,8 @@ 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,
dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &props, G_TYPE_INVALID)) {
const char *scan_type;
data->driver = g_value_dup_string (g_hash_table_lookup (props, "name"));
if (has_multiple_devices)
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"));
if (g_str_equal (scan_type, "swipe"))
data->is_swipe = TRUE;
......@@ -285,9 +303,6 @@ static int do_verify(GMainLoop *loop, pam_handle_t *pamh, DBusGProxy *dev)
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, "VerifyFingerSelected", G_TYPE_STRING, NULL);
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);
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);
release_device(pamh, dev);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment