mirror of
https://gitlab.com/mishakmak/pam-fprint-grosshack.git
synced 2026-04-08 20:03:34 +02:00
device: Add helper routine to load all prints
It might make sense to push this into the storage layer. But, overall, it is OK to live here, and if we do make changes on the storage layer we probably want to change more than just this.
This commit is contained in:
committed by
Marco Trevisan (Treviño)
parent
d07e81acae
commit
bc8ff3e3f6
68
src/device.c
68
src/device.c
@ -1080,6 +1080,45 @@ fprint_device_release (FprintDBusDevice *dbus_dev,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* NOTE: This should probably be moved to the storage layer. */
|
||||
static GPtrArray *
|
||||
load_all_prints (FprintDevice *rdev)
|
||||
{
|
||||
g_autoptr(GPtrArray) res = g_ptr_array_new_with_free_func (g_object_unref);
|
||||
FprintDevicePrivate *priv = fprint_device_get_instance_private (rdev);
|
||||
GSList *user, *users = NULL;
|
||||
|
||||
users = store.discover_users ();
|
||||
|
||||
for (user = users; user; user = user->next)
|
||||
{
|
||||
const char *username = user->data;
|
||||
g_autoptr(GSList) fingers = NULL;
|
||||
GSList *finger;
|
||||
|
||||
fingers = store.discover_prints (priv->dev, username);
|
||||
|
||||
for (finger = fingers; finger; finger = finger->next)
|
||||
{
|
||||
g_autoptr(FpPrint) print = NULL;
|
||||
|
||||
store.print_data_load (priv->dev,
|
||||
GPOINTER_TO_UINT (finger->data),
|
||||
username,
|
||||
&print);
|
||||
|
||||
if (!print)
|
||||
continue;
|
||||
|
||||
g_ptr_array_add (res, g_steal_pointer (&print));
|
||||
}
|
||||
}
|
||||
|
||||
g_slist_free_full (users, g_free);
|
||||
|
||||
return g_steal_pointer (&res);
|
||||
}
|
||||
|
||||
static void
|
||||
report_verify_status (FprintDevice *rdev,
|
||||
gboolean match,
|
||||
@ -1647,8 +1686,9 @@ try_delete_print (FprintDevice *rdev)
|
||||
{
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(GPtrArray) device_prints = NULL;
|
||||
g_autoptr(GPtrArray) host_prints = NULL;
|
||||
FprintDevicePrivate *priv = fprint_device_get_instance_private (rdev);
|
||||
GSList *users, *user;
|
||||
guint i;
|
||||
|
||||
device_prints = fp_device_list_prints_sync (priv->dev, NULL, &error);
|
||||
if (!device_prints)
|
||||
@ -1663,31 +1703,14 @@ try_delete_print (FprintDevice *rdev)
|
||||
* With randomization if we can't sort them. */
|
||||
g_ptr_array_sort (device_prints, garbage_collect_sort);
|
||||
|
||||
users = store.discover_users ();
|
||||
host_prints = load_all_prints (rdev);
|
||||
|
||||
for (user = users; user; user = user->next)
|
||||
for (i = 0; i < host_prints->len; i++)
|
||||
{
|
||||
const char *username = user->data;
|
||||
g_autoptr(GSList) fingers = NULL;
|
||||
GSList *finger;
|
||||
|
||||
fingers = store.discover_prints (priv->dev, username);
|
||||
|
||||
for (finger = fingers; finger; finger = finger->next)
|
||||
{
|
||||
g_autoptr(FpPrint) print = NULL;
|
||||
guint index;
|
||||
|
||||
store.print_data_load (priv->dev,
|
||||
GPOINTER_TO_UINT (finger->data),
|
||||
username,
|
||||
&print);
|
||||
|
||||
if (!print)
|
||||
continue;
|
||||
|
||||
if (!g_ptr_array_find_with_equal_func (device_prints,
|
||||
print,
|
||||
g_ptr_array_index (host_prints, i),
|
||||
(GEqualFunc) fp_print_equal,
|
||||
&index))
|
||||
continue;
|
||||
@ -1695,9 +1718,6 @@ try_delete_print (FprintDevice *rdev)
|
||||
/* Found an equal print, remove it */
|
||||
g_ptr_array_remove_index (device_prints, index);
|
||||
}
|
||||
}
|
||||
|
||||
g_slist_free_full (users, g_free);
|
||||
|
||||
g_debug ("Device has %d prints stored that we do not need", device_prints->len);
|
||||
if (device_prints->len == 0)
|
||||
|
||||
Reference in New Issue
Block a user