forked from uunicorn/python-validity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbus-service.py
162 lines (125 loc) · 4.96 KB
/
dbus-service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
from threading import Thread
from gi.repository import GLib
from pydbus import SystemBus
from pydbus.generic import signal
import pkg_resources
from time import sleep
from prototype import *
from proto97.db import subtype_to_string
from proto97.sensor import cancel_capture
import pwd
print("Starting up")
loop = GLib.MainLoop()
usb.quit = lambda e: loop.quit()
def uname2identity(uname):
if uname == '':
# For some reason Gnome enrollment UI does not send the user name
# (it also ignores our num-enroll-stages attribute). I probably should upgrade Gnome
print('No username specified. ')
uname = 'unicorn'
pw=pwd.getpwnam(uname)
sidstr='S-1-5-21-111111111-1111111111-1111111111-%d' % pw.pw_uid
return sid_from_string(sidstr)
class AlreadyInUse(Exception):
__name__ = 'net.reactivated.Fprint.Error.AlreadyInUse'
class Device():
name = 'Validity sensor'
def __init__(self):
setattr(self, 'num-enroll-stages', 7)
setattr(self, 'scan-type', 'press')
self.capturing = False
def Claim(self, usr):
print('In Claim %s' % usr)
def Release(self):
print('In Release')
self.caimed = False
def ListEnrolledFingers(self, usr):
try:
print('In ListEnrolledFingers %s' % usr)
usr=db.lookup_user(uname2identity(usr))
if usr == None:
print('User not found on this device')
return []
rc = [subtype_to_string(f['subtype']) for f in usr.fingers]
print(repr(rc))
return rc
except Exception as e:
loop.quit()
raise e
def do_scan(self):
if self.capturing:
return
try:
self.capturing = True
z=identify()
self.VerifyStatus('verify-match', True)
except Exception as e:
self.VerifyStatus('verify-no-match', True)
#loop.quit();
raise e
finally:
self.capturing = False
def VerifyStart(self, finger_name):
print('In VerifyStart %s' % finger_name)
Thread(target=lambda: self.do_scan()).start()
#self.do_scan()
def VerifyStop(self):
print('In VerifyStop')
cancel_capture()
def DeleteEnrolledFingers(self, user):
print('In DeleteEnrolledFingers %s' % user)
usr=db.lookup_user(uname2identity(user))
if usr == None:
print('User not found on this device')
return
db.del_record(usr.dbid)
def do_enroll(self, finger_name):
# it is pointless to try and remember username passed in claim as Gnome does not seem to be passing anything useful anyway
try:
# hardcode the username and finger for now
z=enroll(uname2identity('unicorn'), 0xf5)
print('Enroll was successfull')
self.EnrollStatus('enroll-completed', True)
except Exception as e:
self.EnrollStatus('enroll-failed', True)
#loop.quit();
raise e
def EnrollStart(self, finger_name):
print('In EnrollStart %s' % finger_name)
Thread(target=lambda: self.do_enroll(finger_name)).start()
def EnrollStop(self):
print('In EnrollStop')
VerifyFingerSelected = signal()
VerifyStatus = signal()
EnrollStatus = signal()
class Manager():
def GetDevices(self):
print('In GetDevices')
return ['/net/reactivated/Fprint/Device/0']
def GetDefaultDevice(self):
print('In GetDefaultDevice')
return '/net/reactivated/Fprint/Device/0'
def readif(fn):
with open('/usr/share/dbus-1/interfaces/' + fn, 'rb') as f:
# for some reason Gio can't seem to handle XML entities declared inline
return f.read().decode('utf-8') \
.replace('&ERROR_CLAIM_DEVICE;', 'net.reactivated.Fprint.Error.ClaimDevice') \
.replace('&ERROR_ALREADY_IN_USE;', 'net.reactivated.Fprint.Error.AlreadyInUse') \
.replace('&ERROR_INTERNAL;', 'net.reactivated.Fprint.Error.Internal') \
.replace('&ERROR_PERMISSION_DENIED;', 'net.reactivated.Fprint.Error.PermissionDenied') \
.replace('&ERROR_NO_ENROLLED_PRINTS;', 'net.reactivated.Fprint.Error.NoEnrolledPrints') \
.replace('&ERROR_NO_ACTION_IN_PROGRESS;', 'net.reactivated.Fprint.Error.NoActionInProgress') \
.replace('&ERROR_INVALID_FINGERNAME;', 'net.reactivated.Fprint.Error.InvalidFingername') \
.replace('&ERROR_NO_SUCH_DEVICE;', 'net.reactivated.Fprint.Error.NoSuchDevice')
Device.dbus=[readif('net.reactivated.Fprint.Device.xml')]
Manager.dbus=[readif('net.reactivated.Fprint.Manager.xml')]
bus = SystemBus()
bus.publish('net.reactivated.Fprint',
('/net/reactivated/Fprint/Manager', Manager()),
('/net/reactivated/Fprint/Device/0', Device())
)
open97()
usb.trace_enabled = True
tls.trace_enabled = True
loop.run()
print("Normal exit")