Commit graph

555 commits

Author SHA1 Message Date
Benjamin Berg
ebfcbdd13e pam: Use %d with errno instead of %m
Otherwise GCC warns sometimes, and it is easy enough to replace the use
of %m.
2020-12-01 09:00:55 +00:00
Benjamin Berg
ec7376d7e6 meson: Fix CFLAGS use by using add_project_arguments
It seems that meson will not always apply the CFLAGS as defined through
the environment if "c_args=" is used in the default_options array for
the project() call.

Switching to add_project_arguments solves this problem.

See https://github.com/mesonbuild/meson/issues/8037
2020-12-01 09:00:55 +00:00
Marco Trevisan (Treviño)
df568e1ce1 net.reactivated.Fprint: Explicitly allow basic D-Bus APIs 2020-11-28 20:29:57 +00:00
Marco Trevisan (Treviño)
7ee61393ec net.reactivated.Fprint: Only allow clients to send messages with fprintd iface to us
In the way the rule is currently set it would allow clients to send
messages with the fprintd interface to any other service, while we only
allow them to be redirected to fprintd itself.

This was causing a debian linter failure [1].

[1] https://lintian.debian.org/tags/dbus-policy-without-send-destination.html
2020-11-28 20:29:57 +00:00
Marco Trevisan (Treviño)
57ca0dc95e tests/pam: Don't run PAM tests in parallel
Given they could re-use the same pam-wrapper temporary dir, it's better
to avoid running them concurrently.
2020-11-27 19:30:08 +01:00
Marco Trevisan (Treviño)
85ba309e9d tests: Remove pam-wrapper temporary folder on test completion
PAM wrapper creates /tmp/pam.X files during its execution (strictly as
it does not follow $TMPDIR either), however given the low number of
combinations, we may end up in re-using the same pam.* folder during
meson test, causing a failure.

As per this, remove these temporary files on tearDown so that we won't
try reusing the same folder multiple times.
2020-11-27 19:12:06 +01:00
Marco Trevisan (Treviño)
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
Marco Trevisan (Treviño)
5e18d46971 Revert "meson: Bump polkit dependency to 0.114"
We only depend on newer polkit for auto-pointers usage, so it's not
worth to bump its dependency just for them

This reverts commit a8bd2bc25e.
2020-11-27 18:18:51 +01:00
Marco Trevisan (Treviño)
a8bd2bc25e meson: Bump polkit dependency to 0.114
It's the first one supporting auto-pointers
2020-11-27 17:53:58 +01:00
Benjamin Berg
88a627f187 Release 1.90.4 2020-11-27 14:26:12 +01:00
Benjamin Berg
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
Benjamin Berg
c5a3089f89 device: Remove some debug spew
Closes: #89
2020-11-25 19:09:02 +01:00
Benjamin Berg
5de1261df6 device: Re-fetch session data after synchronous operation
As the mainloop is iterated, the session-data may be modified while the
client vanished handler is running. Re-fetch the session data to avoid
seeing an old state and closing the device a second time.

See: https://gitlab.freedesktop.org/libfprint/fprintd/-/issues/87#note_706357
2020-11-25 19:09:02 +01:00
Benjamin Berg
e5c82d7b96 device: Throw a critical warning if the device was not cleaned up
On finalization, the device should always be cleaned up properly (no
data associated with an action may be left). Show a critical warning if
this is not the case, as it indicates a programming error.
2020-11-25 19:09:02 +01:00
Benjamin Berg
9c842e2c2f manager: Fix leak of FprintDevice reference
When adding a device a reference was leaked.
2020-11-25 19:09:02 +01:00
Benjamin Berg
ec5cce083c device: Fix leaks on device finalization 2020-11-25 19:09:02 +01:00
Benjamin Berg
ab8118bde2 tests: Add device removal test 2020-11-25 19:09:00 +01:00
Benjamin Berg
08fb209aed manager: Fix unexport of removed devices
The correct way to unexport the object again is to unexported it on the
manager rather than on the interface skeleton. This fixes notifications
about device removal on DBus.
2020-11-25 19:08:20 +01:00
Benjamin Berg
6eb9f263fd device: Disconnect authorization callback and remove clients
Add a dispose function to disconnect the authorization callback and
remove all clients (i.e. unwatch their bus names) before destroying the
hash table.
2020-11-25 19:08:20 +01:00
Benjamin Berg
74d05e7996 device: Destroy auth object in finalize 2020-11-25 19:08:20 +01:00
Benjamin Berg
83cd09ba2f device: Unwatch names when removing them
If a device is unplugged/destroyed while a client is using it, then we
would still end up watching the name. The vanish notification will then
access the destroyed FprintDevice object.

Fix this by unwatching the bus name when removing the client entry from
the dictionary.
2020-11-25 19:08:20 +01:00
Benjamin Berg
8ed77829a7 tests: Add test for a client vanishing during claim
Note that this test only works if the virtual_image driver opens up a
window for race condition by delaying the open callback.
2020-11-25 19:05:47 +01:00
Benjamin Berg
b63c76319f device: Make possible client vanished race testable using critical
The tests cannot currently parse the logs of fprintd. This means we need
to rely on fprintd aborting when a condition is hit that needs to be
tested.

This makes certain possible races when clients vanish testable.
2020-11-25 19:05:46 +01:00
Benjamin Berg
fd9a86eca4 tests: Fail test if return code is less than 0
This means that the application received a signal.
2020-11-25 19:04:44 +01:00
Marco Trevisan (Treviño)
38ba7199b7 utils: Use auto-pointers 2020-11-13 13:32:51 +01:00
Marco Trevisan (Treviño)
827baff301 enroll: Cleanup error with autoptr 2020-11-13 13:32:51 +01:00
Marco Trevisan (Treviño)
6a5d46c8b0 file_storage: Use autopointers 2020-11-13 13:32:51 +01:00
Marco Trevisan (Treviño)
1ae0f4926d device: Always use auto-pointers
Remove manual memory management when possible, using new GLib facilities

In a few cases, avoid creating a temporary GError instead.
2020-11-13 13:32:31 +01:00
Marco Trevisan (Treviño)
e1c2698807 main: Use more auto-pointers 2020-11-11 11:40:51 +01:00
Benjamin Berg
b14bfd8226 device: Implement lock-free session getting scheme
Add a scheme that allows getting and referencing the current session
data while also adding a reference at the same time. This allows getting
the session and using the constant attributes from outside the main
thread without worrying about it being destroyed.

Implement the getter/setter in a safe way by marking the pointer as
invalid while we get the reference.
2020-11-11 11:35:13 +01:00
Benjamin Berg
1e2f360ade device: Fix possible race condition when checking claimed state
We already check the claimed state in advance during authorization. This
makes sense, as we can avoid authorization if the API has been used
incorrectly. However, as the mainloop is running and handling other
request the claimed state might change at any point until the method
handler is actually running.

As such, check the claimed state again in each method. Doing so fixes
the possible race condition.
2020-11-10 14:45:59 +01:00
Marco Trevisan (Treviño)
778a8540aa device.policy: Use auth-self-keep for enrollment
When user is requested for enrolling, we should ask for password as
anyone who has physical access to the machine could otherwise enroll
its own fingers, and have access to it.

Fixes #5
2020-11-10 14:45:59 +01:00
Marco Trevisan (Treviño)
4e707f0d31 manager: Use GEnum to register DBus errors from FprintError
Given that mk_genenum already parses FprintError, add the nick metadata
to the errors so that it matches the wanted DBus error and automatically
generate the errors list.

In this way we'll have to only touch one definition to get everything
updated
2020-11-10 14:45:59 +01:00
Marco Trevisan (Treviño)
4c78012103 device: Use meson to generate fprint device permission flags 2020-11-10 14:45:59 +01:00
Marco Trevisan (Treviño)
e59f3cbc4f device: Use GFlags to handle permission types easily as flags
And thanks to the GEnumValues we can easily get their nick string from
them that we can pass to Polkit
2020-11-10 14:45:59 +01:00
Marco Trevisan (Treviño)
1a860aa882 tests/fprintd: Add tests ensuring that concurrent calls to fprintd work
Simulate the case in which multiple users are trying to access a device
at the same time, verifying that the access is granted only to the one
that first completes the authorization phase and that no other client is
then allowed.
2020-11-10 14:45:59 +01:00
Marco Trevisan (Treviño)
a183b779ec tests/fprintd: Make easier to call device methods asynchronously 2020-11-10 14:45:59 +01:00
Marco Trevisan (Treviño)
9d6c7eb1a9 dbusmock/polkitd: Add ability to simulate call hangs or delays
Added various methods that allow to make methods to delay to return a
value, both by using timing functions and using a way to manually
stop and restart the calls.

This is mostly done using async callbacks in dbus methods
2020-11-10 14:45:59 +01:00
Marco Trevisan (Treviño)
110c0018a2 tests/fprintd: Make possible to call gdbus client as an async process
As per this refactor the sync call we already had so that reuses the
same code.
2020-11-10 14:45:59 +01:00
Marco Trevisan (Treviño)
5611317c72 tests: Add standalone PolkitD implementation
We need to be able to hack this to be an async daemon to perform some
multi-thread tests, so replacing default implementation with a simple
one that for now just does same of default
2020-11-10 14:45:59 +01:00
Marco Trevisan (Treviño)
0904c8a527 tests/fprintd: Ensure we can claim and release with only the verify permission 2020-11-10 14:45:59 +01:00
Marco Trevisan (Treviño)
a681996d1d device: Check Polkit actions asynchronously using skeleton authorize method
GDBus generated interface skeletons support natively an authorization
method that allows to filter calls before we get into the method
callback and that gets called into the call thread, before we go back
to main thread.

As per this, we can move all the polkit and other authorization checks
into this callback so that method handlers are now just assuming they're
the right to perform the requested operation.

As per the fact we'll share some data between another thread and the
callbacks, we will need to introduce some locking mechanism to ensure
safe data access.

This might be reduced by moving the claiming checks back to the method,
but would lead errors to be handled in different ordering, and so the
user to be requested for a password, and then - in case fail.
This can still happen now, but only if there are concurrent requests.
2020-11-10 14:45:59 +01:00
Marco Trevisan (Treviño)
4e7cf47a3d device: Get sender from invocation instead that during username check
We now can get an invocation-owned sender at any moment with GDBus, so
there's no point of getting it as optional return-out value from the
username check function.
2020-11-10 14:45:59 +01:00
Marco Trevisan (Treviño)
9d3f3fcaca device: Use some #define's for polkit supported actions
Avoid repeating the same strings everywhere that might just lead to
errors, use define's instead.
2020-11-10 14:45:59 +01:00
Marco Trevisan (Treviño)
30474a6546 manager: Add GDBus object manager
This is not used right now in all its full possibilities, but will make
devices hotplug support easier to implement and handle at client-side
level.

As per this we can stop doing the manual tracking of the devices.
2020-11-10 14:45:59 +01:00
Marco Trevisan (Treviño)
93bad82540 fprintd: Use GDBus codegen based implementation
Fprintd is dependent on the deprecated dbus-glib, also this doesn't provide
various features we can take advantage of, like the ones for async
authentication mechanism.

So, remove all the dbus-glib dependencies and simplify the code, but without
any further refactor, and keeping everything as it used to work, while this
will give room for further improvements in subsequent commits.

Internally, we just use dbus-codegen to generate the skeletons, and we
use the generated FprintdDBusManager with composition, while we
implement the device skeleton interface in FprintDevice, so that we
don't have to use it as a proxy, and keep being closer to what it used
to be with dbus-glib.

Fixes: #61
2020-11-10 14:45:59 +01:00
Benjamin Berg
e224913b80 Revert "data: Add additional fprintd lockdown"
The current lockdown rules prevent USB devices from being accessed and
cause threading to not work.
As such, revert them until it is clear on how/if we can apply these
measures. It is primarily not clear on how to prevent fork/clone as
fprintd does not need those.

This reverts commit 2fd86624e5.

See: #82
2020-11-10 12:27:38 +00:00
Marco Trevisan (Treviño)
b2cae5cccf tests/fprintd: Check that identification with multiple images works 2020-11-06 11:06:25 +01:00
Marco Trevisan (Treviño)
3419901f65 build: Don't add the utils tests under the daemon suite 2020-11-04 21:06:13 +01:00
Marco Trevisan (Treviño)
c85ca09e35 tests/fprintd-utils: Ensure that we exit with error if we have no device 2020-11-04 21:06:13 +01:00