mirror of
https://gitlab.com/mishakmak/pam-fprint-grosshack.git
synced 2026-04-08 20:03:34 +02:00
device: Clear storage before enrolling the first print
Clear the device storage before we enroll the first print. At that point, we know that the storage should be completely empty and we have no way of deleting "garbage" prints later if the device does not support listing prints.
This commit is contained in:
committed by
Benjamin Berg
parent
9e8139e6d4
commit
f44233461f
23
src/device.c
23
src/device.c
@ -1797,8 +1797,9 @@ enroll_cb (FpDevice *dev, GAsyncResult *res, void *user_data)
|
|||||||
* enough. */
|
* enough. */
|
||||||
if (g_error_matches (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_DATA_FULL))
|
if (g_error_matches (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_DATA_FULL))
|
||||||
{
|
{
|
||||||
g_debug ("Device storage is full, trying to garbage collect old prints");
|
g_debug ("Device storage is full");
|
||||||
if (try_delete_print (rdev))
|
if (fp_device_has_feature (priv->dev, FP_DEVICE_FEATURE_STORAGE_LIST) &&
|
||||||
|
try_delete_print (rdev))
|
||||||
{
|
{
|
||||||
/* Success? Then restart the operation */
|
/* Success? Then restart the operation */
|
||||||
fp_device_enroll (priv->dev,
|
fp_device_enroll (priv->dev,
|
||||||
@ -1939,6 +1940,15 @@ enroll_identify_cb (FpDevice *dev, GAsyncResult *res, void *user_data)
|
|||||||
enroll_start (rdev);
|
enroll_start (rdev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
is_first_enrollment (FprintDevice * rdev)
|
||||||
|
{
|
||||||
|
g_autoptr(GPtrArray) host_prints = NULL;
|
||||||
|
host_prints = load_all_prints (rdev);
|
||||||
|
|
||||||
|
return host_prints->len == 0;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
fprint_device_enroll_start (FprintDBusDevice *dbus_dev,
|
fprint_device_enroll_start (FprintDBusDevice *dbus_dev,
|
||||||
GDBusMethodInvocation *invocation,
|
GDBusMethodInvocation *invocation,
|
||||||
@ -1991,6 +2001,15 @@ fprint_device_enroll_start (FprintDBusDevice *dbus_dev,
|
|||||||
priv->enroll_data = finger;
|
priv->enroll_data = finger;
|
||||||
priv->current_action = ACTION_ENROLL;
|
priv->current_action = ACTION_ENROLL;
|
||||||
|
|
||||||
|
if (is_first_enrollment (rdev))
|
||||||
|
{
|
||||||
|
g_autoptr(GError) clear_err = NULL;
|
||||||
|
|
||||||
|
if (!fp_device_clear_storage_sync (priv->dev, NULL, &clear_err))
|
||||||
|
g_warning ("Failed to clear storage before first enrollment: %s",
|
||||||
|
clear_err->message);
|
||||||
|
}
|
||||||
|
|
||||||
if (fp_device_has_feature (priv->dev, FP_DEVICE_FEATURE_IDENTIFY))
|
if (fp_device_has_feature (priv->dev, FP_DEVICE_FEATURE_IDENTIFY))
|
||||||
{
|
{
|
||||||
g_autoptr(GPtrArray) all_prints = load_all_prints (rdev);
|
g_autoptr(GPtrArray) all_prints = load_all_prints (rdev);
|
||||||
|
|||||||
@ -850,7 +850,7 @@ class FPrintdVirtualStorageDeviceBaseTest(FPrintdVirtualDeviceBaseTest):
|
|||||||
self.assertIn(command, ['INSERT', 'REMOVE', 'SCAN', 'ERROR', 'RETRY',
|
self.assertIn(command, ['INSERT', 'REMOVE', 'SCAN', 'ERROR', 'RETRY',
|
||||||
'FINGER', 'UNPLUG', 'SLEEP', 'SET_ENROLL_STAGES', 'SET_SCAN_TYPE',
|
'FINGER', 'UNPLUG', 'SLEEP', 'SET_ENROLL_STAGES', 'SET_SCAN_TYPE',
|
||||||
'SET_CANCELLATION_ENABLED', 'LIST', 'IGNORED_COMMAND',
|
'SET_CANCELLATION_ENABLED', 'LIST', 'IGNORED_COMMAND',
|
||||||
'SET_KEEP_ALIVE'])
|
'SET_KEEP_ALIVE', 'CONT'])
|
||||||
|
|
||||||
with Connection(self.sockaddr) as con:
|
with Connection(self.sockaddr) as con:
|
||||||
res = self._send_command(con, command, *args)
|
res = self._send_command(con, command, *args)
|
||||||
@ -935,6 +935,8 @@ class FPrintdVirtualStorageDeviceTests(FPrintdVirtualStorageDeviceBaseTest):
|
|||||||
'FP1-20201231-7-ABCDEFGH-testuser' : 'right-index-finger',
|
'FP1-20201231-7-ABCDEFGH-testuser' : 'right-index-finger',
|
||||||
'no-metadata-new' : 'left-middle-finger',
|
'no-metadata-new' : 'left-middle-finger',
|
||||||
}
|
}
|
||||||
|
# Explicitly fail initial cleanup (not needed, but faster)
|
||||||
|
self.send_command('ERROR', 0)
|
||||||
for i, f in enrolled_prints.items():
|
for i, f in enrolled_prints.items():
|
||||||
self.enroll_print(i, f)
|
self.enroll_print(i, f)
|
||||||
|
|
||||||
@ -973,6 +975,8 @@ class FPrintdVirtualStorageDeviceTests(FPrintdVirtualStorageDeviceBaseTest):
|
|||||||
self.device.Claim('(s)', 'testuser')
|
self.device.Claim('(s)', 'testuser')
|
||||||
|
|
||||||
self.assertEqual(self.get_stored_prints(), ['stored-print'])
|
self.assertEqual(self.get_stored_prints(), ['stored-print'])
|
||||||
|
# Explicitly fail initial cleanup (not needed, but faster)
|
||||||
|
self.send_command('ERROR', 0)
|
||||||
self.device.EnrollStart('(s)', 'right-thumb')
|
self.device.EnrollStart('(s)', 'right-thumb')
|
||||||
self.send_image('stored-print') # During identify
|
self.send_image('stored-print') # During identify
|
||||||
self.wait_for_result('enroll-stage-passed')
|
self.wait_for_result('enroll-stage-passed')
|
||||||
@ -990,6 +994,8 @@ class FPrintdVirtualStorageDeviceTests(FPrintdVirtualStorageDeviceBaseTest):
|
|||||||
self.device.Claim('(s)', 'testuser')
|
self.device.Claim('(s)', 'testuser')
|
||||||
|
|
||||||
self.assertEqual(self.get_stored_prints(), ['stored-print'])
|
self.assertEqual(self.get_stored_prints(), ['stored-print'])
|
||||||
|
# Explicitly fail initial cleanup (not needed, but faster)
|
||||||
|
self.send_command('ERROR', 0)
|
||||||
self.device.EnrollStart('(s)', 'right-thumb')
|
self.device.EnrollStart('(s)', 'right-thumb')
|
||||||
self.send_image('stored-print') # During identify
|
self.send_image('stored-print') # During identify
|
||||||
self.send_error(FPrint.DeviceError.PROTO) # During garbage collecting
|
self.send_error(FPrint.DeviceError.PROTO) # During garbage collecting
|
||||||
@ -3065,6 +3071,10 @@ class FPrintdUtilsTest(FPrintdVirtualStorageDeviceBaseTest):
|
|||||||
self.set_keep_alive(True)
|
self.set_keep_alive(True)
|
||||||
self.device.Release()
|
self.device.Release()
|
||||||
|
|
||||||
|
# Open and clear storage
|
||||||
|
self.send_command('CONT')
|
||||||
|
self.send_command('CONT')
|
||||||
|
|
||||||
finger_name = self.get_finger_name(FPrint.Finger.LEFT_THUMB)
|
finger_name = self.get_finger_name(FPrint.Finger.LEFT_THUMB)
|
||||||
enroll, out = self.util_start('enroll', [self.get_current_user(),
|
enroll, out = self.util_start('enroll', [self.get_current_user(),
|
||||||
'-f', finger_name])
|
'-f', finger_name])
|
||||||
@ -3105,6 +3115,10 @@ class FPrintdUtilsTest(FPrintdVirtualStorageDeviceBaseTest):
|
|||||||
self.set_keep_alive(True)
|
self.set_keep_alive(True)
|
||||||
self.device.Release()
|
self.device.Release()
|
||||||
|
|
||||||
|
# Open and clear storage
|
||||||
|
self.send_command('CONT')
|
||||||
|
self.send_command('CONT')
|
||||||
|
|
||||||
finger_name = self.get_finger_name(FPrint.Finger.LEFT_MIDDLE)
|
finger_name = self.get_finger_name(FPrint.Finger.LEFT_MIDDLE)
|
||||||
enroll, out = self.util_start('enroll', [self.get_current_user(),
|
enroll, out = self.util_start('enroll', [self.get_current_user(),
|
||||||
'-f', finger_name])
|
'-f', finger_name])
|
||||||
|
|||||||
Reference in New Issue
Block a user