mirror of
https://gitlab.com/mishakmak/pam-fprint-grosshack.git
synced 2026-04-08 20:03:34 +02:00
dbusmock/fprintd: Support more complex verify scripts
This now allows: * Sending signals before and after method return * Exiting the daemon * Emulating NoEnrolledPrints DBus method error Co-authored-by: Benjamin Berg <bberg@redhat.com>
This commit is contained in:
committed by
Benjamin Berg
parent
5ccb9ba0ec
commit
3242b99410
@ -18,6 +18,7 @@ __email__ = 'hadess@hadess.net'
|
|||||||
__copyright__ = '(c) 2020 Red Hat Inc.'
|
__copyright__ = '(c) 2020 Red Hat Inc.'
|
||||||
__license__ = 'LGPL 3+'
|
__license__ = 'LGPL 3+'
|
||||||
|
|
||||||
|
import sys
|
||||||
from gi.repository import GLib
|
from gi.repository import GLib
|
||||||
import dbus
|
import dbus
|
||||||
import asyncio
|
import asyncio
|
||||||
@ -214,9 +215,26 @@ def can_verify_finger(device, finger_name):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def device_emit_signal(device, *args):
|
def glib_sleep(timeout):
|
||||||
print("emitting signal", *args)
|
waiting = True
|
||||||
device.EmitSignal(*args)
|
|
||||||
|
def done_waiting():
|
||||||
|
nonlocal waiting
|
||||||
|
waiting = False
|
||||||
|
|
||||||
|
GLib.timeout_add(timeout, done_waiting)
|
||||||
|
while (waiting):
|
||||||
|
GLib.main_context_default().iteration(True)
|
||||||
|
|
||||||
|
def device_run_script(device, result, done):
|
||||||
|
if result == 'MOCK: quit':
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Emit signal
|
||||||
|
device.EmitSignal(DEVICE_IFACE, 'VerifyStatus', 'sb', [
|
||||||
|
result,
|
||||||
|
done
|
||||||
|
])
|
||||||
|
|
||||||
@dbus.service.method(DEVICE_IFACE,
|
@dbus.service.method(DEVICE_IFACE,
|
||||||
in_signature='s', out_signature='')
|
in_signature='s', out_signature='')
|
||||||
@ -252,15 +270,38 @@ def VerifyStart(device, finger_name):
|
|||||||
device.selected_finger
|
device.selected_finger
|
||||||
])
|
])
|
||||||
|
|
||||||
if device.verify_script is not None and len(device.verify_script) > 0:
|
error = None
|
||||||
|
base_delay = 0
|
||||||
|
while device.verify_script is not None and len(device.verify_script) > 0:
|
||||||
result, done, timeout = device.verify_script.pop(0)
|
result, done, timeout = device.verify_script.pop(0)
|
||||||
GLib.timeout_add(timeout,
|
|
||||||
device_emit_signal,
|
# We stop when "timeout >= 0 and done"
|
||||||
device,
|
if result == 'MOCK: no-prints':
|
||||||
DEVICE_IFACE, 'VerifyStatus', 'sb', [
|
# Special case to change return value of DBus call, ignores timeout
|
||||||
result,
|
error = dbus.exceptions.DBusException(
|
||||||
done
|
'No enrolled prints for user \'%s\'' % device.claimed_user,
|
||||||
])
|
name='net.reactivated.Fprint.Error.NoEnrolledPrints')
|
||||||
|
|
||||||
|
elif timeout < 0:
|
||||||
|
# Negative timeouts mean emitting before the DBus call returns
|
||||||
|
device_run_script(device, result, done)
|
||||||
|
glib_sleep(-timeout)
|
||||||
|
|
||||||
|
else:
|
||||||
|
# Positive or zero means emitting afterwards the given timeout
|
||||||
|
base_delay += timeout
|
||||||
|
GLib.timeout_add(base_delay,
|
||||||
|
device_run_script,
|
||||||
|
device,
|
||||||
|
result,
|
||||||
|
done)
|
||||||
|
|
||||||
|
# Stop processing commands when the done flag is set
|
||||||
|
if done:
|
||||||
|
break
|
||||||
|
|
||||||
|
if error:
|
||||||
|
raise error
|
||||||
|
|
||||||
@dbus.service.method(DEVICE_MOCK_IFACE,
|
@dbus.service.method(DEVICE_MOCK_IFACE,
|
||||||
in_signature='sb', out_signature='')
|
in_signature='sb', out_signature='')
|
||||||
|
|||||||
Reference in New Issue
Block a user