Commit Graph

233 Commits

Author SHA1 Message Date
2b81184b42 device: Fail with any non-zero return value on storage print_data_save()
When saving the prints we use g_file_set_contents under the hood and in
case return its error code that is a positive value.

So in such case we don't fail if we have a write failure at the end of
the enrollment.

While we could ensure in file storage to always return a negative value,
it's always better to ensure that is has to be 0 when we didn't get an
error.

Add a test checking for this case.
2021-01-27 17:52:05 +01:00
157bcf0ff5 device: Check if the device is open if we didn't fail in claiming it
When claiming a device for delete operation we'd not get an error in
case we can claim it but it's not already claimed, so in such case we
should explicitly check that the device has been opened.
2021-01-25 19:15:09 +01:00
72a2504fc4 device: Wait device to finish for a timeout before completing VerifyStop
When a device has reported the verification status the client should
call VerifyStop to stop the device, however this under the hood may lead
to a premature cancellation, causing the device not to react as expected
in case the finger is still on the sensor or in case it may return to us
some errors that we may want to handle (like the data-missing one).

So, in case we are about to stop the verification and the operation is
still in process, wait for a maximum timeout before proceed to the
cancellation.

However, while waiting, the action may be also cancelled because of a
call to Release() or because the client vanished, and in such case we
have to ensure that the current invocation is saved for being invoked by
stoppable_action_completed() when callback will return. That will also
unset it, and that's a clear indication for us that it has been already
consumed, and thus that we can just return doing nothing else.

Fixes: #100
2021-01-25 18:18:40 +01:00
f87cb27163 device: Fix debug statement string ordering and be more consistent
We were inverting the values in the `Authorization granted` message, so
be consistent in the ordering we show the message.
2021-01-25 18:18:40 +01:00
457cbd46cd device: Stop any further EnrollStop/VerifyStop request once we got one
In case we get concurrent requests on EnrollStart/EnrollStop we'd just
continue with the operation, making the first processed request to start
the process and the second to hang (in code before the introduction of
stoppable_action_stop()) or to crash (in the current code).

So in such case we should always check that we're not handling already
the request, by checking priv->current_cancel_invocation value.

Add tests to verify the race.
2021-01-25 18:18:39 +01:00
32b70c0edc device: Add an unique function to check if we can stop the current action 2021-01-25 18:18:13 +01:00
ff798edc51 device: Move duplicated code for stopping a stoppable action into a function
We can handle this in a generic way for all the cancellable cases.
2021-01-22 22:06:07 +01:00
56436fb8b1 device: Always use stoppable_action_completed to terminate actions
Avoid having repeated code for doing the same, nothing changes as before
we were doing the same only in case we had not a cancellable set.
2021-01-22 22:06:01 +01:00
dbf01399ad device: Throw an error if we failed to delete a device storage print
Although this error is not fatal as the local print reference has been
properly removed.
2021-01-22 15:19:21 +01:00
e0a643f3b9 device: Return more specific error if we failed cleaning up the storage 2021-01-22 15:19:21 +01:00
76c6e9e030 device: Return errors on deletion of prints from storage 2021-01-22 15:17:57 +01:00
5dde80c136 device: Expose an error if we are not able to remove a print from storage
This is case we should notify, as in such case the print will still
usable.
2021-01-22 15:17:57 +01:00
7d87f5e664 device: Set an error if trying to delete a print that is not enrolled 2021-01-22 15:17:57 +01:00
fd72c0b81b device: Support deleting a single fingerprint for user
Add a method to delete only a Fingerprint for a device, this is required
by they g-c-c UI design and at the same time it reflects the libfprint
API, where so far only a fingerprint at time can be deleted.
2021-01-22 15:17:57 +01:00
1835d99265 device: Expose finger status as DBus properties
libfprint v1.90.4 introduced a new finger status API to expose to the UI
the finger status on sensor.

Add two new properties to the Device interface that represent the
possible values.

Add new tests.
2021-01-22 14:10:04 +00:00
30eaaf2def device: Take advantage of the DBus skeleton properties caching
The device DBus skeleton interface already implements caching for the
properties and can smartly handle their update sending (batched) dbus
events on changes.

Even if the default properties are only read only and we don't care, we
are going to introduce properties that will change values, and so having
the skeleton to handle this for us is quite convenient.

Given that we don't really need to override those properties, we can
just set them at start and leave the skeleton cache to handle the rest.

In case we'd ever need to override them, however the skeleton also
provides a way to override all the properties and to get a reference of
the number of properties it defines, ensuring to keep the order they are
defined.
This would allow us to get back the parent's properties IDs and to use
this to implement ours properties getters/setters using the parent one
as fallback.
2021-01-22 14:10:04 +00:00
00fbf19079 device: Prefer older prints when garbage collecting
This makes garbage collection a bit more predictable overall. Note that
we'll first delete prints that we do not know the age of.

If we cannot sort them by age, then randomize the order so that we don't
end up deleting in the order that the device returned the prints.
2021-01-20 23:25:52 +01:00
938c1aac5a device: Add common stoppable_action_completed function
The stoppable actions (Verify/Enroll) have the same logic during
completion. Create a common function to share this logic instead of
copying it in each of the handlers.

Fixes: #97
2021-01-11 12:59:06 +00:00
48ea3b89c9 file_storage: Cleanup the user storage path when removing prints
Try to remove user and devices directories if they are empty.
2021-01-05 13:07:19 +01:00
4cfa6b5b37 file_storage: Remove debug leftovers and add actual debug statements 2021-01-05 13:07:19 +01:00
c685f0d34c file_storage: Don't return an error if the print doesn't exist
We may just try to remove something isn't there so it's not an actual
error from our POV.
2021-01-05 13:07:19 +01:00
eece834231 file_storage: Do not remove the finger path two times
Return the actual operation error instead
2021-01-05 13:07:19 +01:00
3faaa81257 file_storage: Do not ignore STATE_DIRECTORY if it's set to an actual path 2021-01-05 13:07:19 +01:00
b9cdb58a1a device: Load the current finger print and not always the first print
In the garbage collection code we always ended up to load the first
enrolled print, and this may lead to removing from device storage prints
that are actually in use.
2021-01-05 12:57:55 +01:00
ab8dcfaa61 treewide: fix typos 2021-01-04 11:04:13 +01:00
7c9a04c2ae device: Fix race when client vanishes from bus
We have a condition where a client vanishing instead of cleaning up the
operation using VerifyStop would cause fprintd to hang. This only
happens if the underlying enroll/verify/identify operation has already
finished when the client vanishes.

Fix this by correctly interpreting current_cancellable as a flag for
these operations.

Fixes: #97
2021-01-04 11:00:18 +01:00
7b7aa6e99d device: Fix typos 2021-01-04 09:49:24 +08:00
b624f8c8c7 manager: Do not use unnecessary volatile qualifier on GQuark
As per new GLib in CI image fprintd doesn't build anymore, since
g_once_init_enter now warns about using a volatile value, as this has
never been supposed to be the case, despite its signature [1].

Related to: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1719

[1] https://gitlab.gnome.org/GNOME/glib/-/issues/600
2020-12-19 22:34:12 +01:00
3e81179eca device: Add auto-cleanup function to unset the current action
This is useful in the functions where we have to unset the device's
current action but we may use early-return to handle multiple conditions
such as in open, close and delete functions.
The latest also currently is a bit buggy as it won't reset the state on
some failures.
2020-12-17 16:33:58 +01:00
32ee94c8a0 Add compatibility defines to allow compiling with older glib
We need at least the GFlagsClass autoptr, but just pull in most of the
definitions from libfprint.
2020-12-14 11:30:45 +01:00
18392cba54 manager: Export the object manager in /net/reactivated/Fprint
Given we're going to use an object manager it can just stay at the root
of the project, while it will be just used to manage the devices
2020-12-11 15:30:26 +01:00
783d82f359 device: Expose method name when logging authorization steps 2020-12-11 14:03:37 +00:00
c00a3375d1 device: Use standard names for local errors and remove unused one 2020-12-11 14:03:37 +00:00
f73429f062 fprintd: Reindent the source code following uncrustify rules 2020-12-07 18:41:45 +01:00
22cdc0a7ea device: Always use FpFinger instead of a mixture of it and finger numbers
We already use FpFinger for storage operations and prints management,
but internally we keep still using the old finger number, that uses
different values for invalid data.

Let's be consistent, and always use FpFinger everywhere.
2020-12-07 15:27:14 +01:00
a4b06c2219 device: Emit VerifyFingerSelected after the method returned
In order to be race free, clients need to ignore all signals until after
the DBus method to start verification has returned. So the signal must
be emitted later than it currently is.
2020-12-07 15:27:14 +01:00
5ccaa094a0 build: Generate fprintd dbus sources using interactive flags
Since we can't depend on newer GLib yet, we patch the generated sources
to generate some new ones with fixed flags.
2020-12-07 15:14:07 +01:00
fc7e4d0e5c device: Do not require authentication for release/stop
If someone has started an operation, then we don't really need to
confirm they are permitted to stop it again. Not doing this has the
advantage that we cannot run into a second interactive authorization
step accidentally.
2020-12-07 15:14:07 +01:00
583cd870d8 device: Use a common error function if an action is ongoing
There is no need to dupliate the code. Just create one function that
sets an error and returns FALSE if action is not ACTION_NONE.
2020-12-07 12:02:32 +01:00
2ca2d5e62c device: Use a switch to check current action so we can be more selective
For example we were allowing to verify stop while doing other actions
different from enrolling (such as delete or open/close).
2020-12-07 12:02:32 +01:00
c5c81a2ea8 device: Add ACTION_DELETE to prevent concurrent operations
Delete needs to operate on the device, so no other actions are permitted
at the same time. And using the libfprint _sync methods does not
guard against reentrance.
2020-12-07 12:02:32 +01:00
2dc3a4e2c5 device: Use more standard naming for local errors 2020-12-07 12:00:58 +01:00
eac171ab0f device: Add separate state for delete which will claim internally
Also rename the different claim states to make them a bit more
understandable.
2020-12-07 12:00:58 +01:00
7533f63a06 device: Move permissions checks per DBus invocation in a single function
This way we can avoid repeating the same checks multiple times, and
we have a single point where we check the permissions needed for method
invocation.
2020-12-07 11:59:42 +01:00
a38917ab26 fprintd: Re-order permissions table by priority and add docs
Given that we could do operations where at least one permission, is
requested, we should give more priority to the weaker ones that are
acceptable and in case raise the level at later points.
2020-12-05 01:01:36 +01:00
a92b8e5f60 device: Always return FALSE if setting an error in Check claimed
We may have a case where the sender matches with the
session's sender but have a session invocation already set.

In such case we set an error, but still return TRUE.
2020-12-05 01:01:36 +01:00
e301779c20 Fix integer signedness mismatches 2020-12-01 09:00:55 +00:00
be5d283a3e device: Remove unused code
The code was left over when adding the function to create the session data.
2020-12-01 09:00:55 +00:00
3f2174676e device: Re-define polkit auto-pointer funcs if not defined
In case we're using an old polkit version that does not support
auto-pointers, we need to re-define such functions manually or fprintd
won't compile.

Given that polkit doesn't provide us version informations in headers we
need to get that from pkg-config
2020-11-27 18:21:29 +01:00
a8818f9bfb device: Do not disconnect g-authorize-method handler
Disconnecting the g-authorize-method handler is not really needed, as it
is a signal from the same object. This basically reverts 6eb9f263fd
(device: Disconnect authorization callback and remove clients) but keeps
the code to clear known clients in the dispose handler.

Closes: #91
2020-11-27 14:23:41 +01:00