Actually check which user was passed to VerifyStart.
This commit is contained in:
parent
33712e9800
commit
eca81e6677
2 changed files with 26 additions and 28 deletions
|
|
@ -4,11 +4,13 @@ import signal
|
||||||
import argparse
|
import argparse
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
|
import pwd
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import dbus
|
import dbus
|
||||||
import dbus.mainloop.glib
|
import dbus.mainloop.glib
|
||||||
import dbus.service
|
import dbus.service
|
||||||
|
from usb import core as usb_core
|
||||||
from binascii import hexlify, unhexlify
|
from binascii import hexlify, unhexlify
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
||||||
|
|
@ -22,7 +24,6 @@ from validitysensor.usb import usb
|
||||||
from validitysensor.sid import sid_from_string
|
from validitysensor.sid import sid_from_string
|
||||||
from validitysensor.db import subtype_to_string, db
|
from validitysensor.db import subtype_to_string, db
|
||||||
from validitysensor.sensor import sensor, reboot, RebootException
|
from validitysensor.sensor import sensor, reboot, RebootException
|
||||||
import pwd
|
|
||||||
|
|
||||||
GLib.threads_init()
|
GLib.threads_init()
|
||||||
|
|
||||||
|
|
@ -30,8 +31,11 @@ INTERFACE_NAME='io.github.uunicorn.Fprint.Device'
|
||||||
|
|
||||||
loop = GLib.MainLoop()
|
loop = GLib.MainLoop()
|
||||||
|
|
||||||
usb.quit = lambda e: loop.quit()
|
class NoEnrolledPrints(dbus.DBusException):
|
||||||
|
_dbus_error_name = 'net.reactivated.Fprint.Error.NoEnrolledPrints'
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__('No enrolled prints found')
|
||||||
|
|
||||||
def uid2identity(uid):
|
def uid2identity(uid):
|
||||||
sidstr='S-1-5-21-111111111-1111111111-1111111111-%d' % uid
|
sidstr='S-1-5-21-111111111-1111111111-1111111111-%d' % uid
|
||||||
|
|
@ -78,7 +82,13 @@ class Device(dbus.service.Object):
|
||||||
in_signature='ss',
|
in_signature='ss',
|
||||||
out_signature='')
|
out_signature='')
|
||||||
def VerifyStart(self, user, finger):
|
def VerifyStart(self, user, finger):
|
||||||
logging.debug('In VerifyStart %s' % finger)
|
logging.debug('In VerifyStart for %s, %s' % (user, finger))
|
||||||
|
|
||||||
|
pw = pwd.getpwnam(user)
|
||||||
|
usr = db.lookup_user(uid2identity(pw.pw_uid))
|
||||||
|
|
||||||
|
if usr == None:
|
||||||
|
raise NoEnrolledPrints()
|
||||||
|
|
||||||
self.VerifyFingerSelected('any')
|
self.VerifyFingerSelected('any')
|
||||||
|
|
||||||
|
|
@ -87,8 +97,16 @@ class Device(dbus.service.Object):
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
try:
|
try:
|
||||||
|
# TODO: pass down the user db record id and implement a proper Sensor.verify() method
|
||||||
usrid, subtype, hsh = sensor.identify(update_cb)
|
usrid, subtype, hsh = sensor.identify(update_cb)
|
||||||
self.VerifyStatus('verify-match', True)
|
if usr.dbid == usrid:
|
||||||
|
self.VerifyStatus('verify-match', True)
|
||||||
|
else:
|
||||||
|
self.VerifyStatus('verify-no-match', True)
|
||||||
|
except usb_core.USBError as e:
|
||||||
|
logging.exception(e)
|
||||||
|
self.VerifyStatus('verify-no-match', True)
|
||||||
|
loop.quit()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception(e)
|
logging.exception(e)
|
||||||
self.VerifyStatus('verify-no-match', True)
|
self.VerifyStatus('verify-no-match', True)
|
||||||
|
|
@ -121,6 +139,10 @@ class Device(dbus.service.Object):
|
||||||
try:
|
try:
|
||||||
sensor.enroll(uid2identity(uid), 0xf5, update_cb) # TODO parse the finger name
|
sensor.enroll(uid2identity(uid), 0xf5, update_cb) # TODO parse the finger name
|
||||||
self.EnrollStatus('enroll-completed', True)
|
self.EnrollStatus('enroll-completed', True)
|
||||||
|
except usb_core.USBError as e:
|
||||||
|
logging.exception(e)
|
||||||
|
self.EnrollStatus('enroll-failed', True)
|
||||||
|
loop.quit()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception(e)
|
logging.exception(e)
|
||||||
self.EnrollStatus('enroll-failed', True)
|
self.EnrollStatus('enroll-failed', True)
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ class Usb():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.interrupt_cb = None
|
self.interrupt_cb = None
|
||||||
self.trace_enabled = False
|
self.trace_enabled = False
|
||||||
self.quit = None
|
|
||||||
self.dev = None
|
self.dev = None
|
||||||
self.cancel = False
|
self.cancel = False
|
||||||
|
|
||||||
|
|
@ -125,29 +124,6 @@ class Usb():
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def int_thread(self):
|
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
resp = self.dev.read(131, 1024, timeout=0)
|
|
||||||
resp = bytes(resp)
|
|
||||||
self.trace('<int< %s' % hexlify(resp).decode())
|
|
||||||
cb=self.interrupt_cb
|
|
||||||
if cb is None:
|
|
||||||
logging.warning('Ignoring spurious interrupt: %s' % hexlify(resp).decode())
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
cb(resp)
|
|
||||||
except Exception as e:
|
|
||||||
logging.warning('Exception on the interrupt thread: %s' % e)
|
|
||||||
except USBError as e:
|
|
||||||
self.trace('<int< Exception on interrupt thread: %s' % repr(e))
|
|
||||||
if self.quit != None:
|
|
||||||
self.quit(e)
|
|
||||||
finally:
|
|
||||||
self.trace('<int< Interrupt thread is dead')
|
|
||||||
|
|
||||||
|
|
||||||
def trace(self, s):
|
def trace(self, s):
|
||||||
if self.trace_enabled:
|
if self.trace_enabled:
|
||||||
logging.debug(s)
|
logging.debug(s)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue