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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
#!/usr/bin/python
import sys
import os
import struct
import socket
import subprocess
import signal
from gi.repository import GLib
from gi.repository import LightDM
display = os.getenv ('DISPLAY');
if display is None:
greeter_id = 'GREETER-?'
elif display.startswith (':'):
greeter_id = 'GREETER-X-%s' % display[1:]
else:
greeter_id = 'GREETER-X-%s' % display
loop = GLib.MainLoop ()
def sigterm_cb (data):
status_notify ('%s TERMINATE SIGNAL=%d' % (greeter_id, signal.SIGTERM))
loop.quit ()
GLib.unix_signal_add (GLib.PRIORITY_DEFAULT, signal.SIGTERM, sigterm_cb, None)
status_socket = None
def status_notify (message):
if status_socket is not None:
status_socket.send (struct.pack ('i', len (message)) + message)
else:
sys.stderr.write ('%s\n' % message)
def request_cb (channel, condition):
length = status_socket.recv (4)
if len (length) == 0:
loop.quit ();
return False
if len (length) > 0:
(l,) = struct.unpack ('i', length)
request = status_socket.recv (l)
r = '%s AUTHENTICATE' % greeter_id
if request == r:
greeter.authenticate (None)
r = '%s AUTHENTICATE USERNAME=' % greeter_id
if request.startswith (r):
greeter.authenticate (request[len(r):])
r = '%s AUTHENTICATE-GUEST' % greeter_id
if request == r:
greeter.authenticate_as_guest ()
r = '%s AUTHENTICATE-AUTOLOGIN' % greeter_id
if request == r:
greeter.authenticate_autologin ()
r = '%s AUTHENTICATE-REMOTE SESSION=' % greeter_id
if request.startswith (r):
greeter.authenticate_remote (request[len(r):], None)
r = '%s RESPOND TEXT=\"' % greeter_id
if request.startswith (r):
greeter.respond (request[len (r):-1])
r = '%s START-SESSION' % greeter_id
if request == r:
if not greeter.start_session_sync (None):
status_notify ('%s SESSION-FAILED' % greeter_id)
r = '%s START-SESSION SESSION=' % greeter_id
if request.startswith (r):
if not greeter.start_session_sync (request[len(r):]):
status_notify ('%s SESSION-FAILED' % greeter_id)
r = '%s LOG-LAYOUT' % greeter_id
if request == r:
layout = LightDM.get_layout ().get_name ()
status_notify ('%s LOG-LAYOUT LAYOUT=%s' % (greeter_id, layout))
r = '%s LOG-LAYOUT USERNAME=' % greeter_id
if request.startswith (r):
username = request[len(r):]
user = LightDM.UserList.get_instance ().get_user_by_name (username)
layout = user.get_layout ()
if layout is None:
layout = ''
status_notify ('%s LOG-LAYOUT USERNAME=%s LAYOUT=%s' % (greeter_id, username, layout))
r = '%s LOG-LANGUAGE USERNAME=' % greeter_id
if request.startswith (r):
username = request[len(r):]
user = lightdm_user_list_get_user_by_name (lightdm_user_list_get_instance (), username)
language = lightdm_user_get_language (user)
if language is None:
language = ''
status_notify ('%s LOG-LANGUAGE USERNAME=%s LANGUAGE=%s' % (greeter_id, username, language))
return True
path = os.getenv ('LIGHTDM_TEST_ROOT') + '/.status-socket'
status_socket = socket.socket (socket.AF_UNIX, socket.SOCK_STREAM)
status_socket.connect (path)
GLib.io_add_watch (status_socket.fileno (), GLib.IO_IN | GLib.IO_HUP, request_cb)
status_notify ('%s START' % greeter_id)
# NOTE: There don't seem to be any good X bindings so we have to mock up our own...
(host, display_number) = display.split (':')
if host == '':
x_socket = socket.socket (socket.AF_UNIX, socket.SOCK_STREAM)
x_socket.connect ('/tmp/.X11-unix/X%s' % display_number)
else:
x_socket = socket.socket (socket.AF_INET, socket.SOCK_STREAM)
x_socket.connect ((host, 6000 + int (display_number)))
authority = subprocess.check_output(['xauth', 'list']).split ()
auth_name = ''
auth_data = ''
if len (authority) >= 3:
auth_name = authority[1]
hex = authority[2]
while len (hex) >= 2:
auth_data += chr (int (hex[:2], 16))
hex = hex[2:]
def pad (value):
if len (value) % 4 != 0:
return value + '\x00' * (4 - len (value) % 4)
else:
return value
x_socket.send (struct.pack ('!cxHHHHxx', 'B', 11, 0, len (auth_name), len (auth_data)) + pad (auth_name) + pad (auth_data))
data = x_socket.recv (1024)
if ord (data[0]) != 1:
status_notify ('%s FAIL-CONNECT-XSERVER' % greeter_id)
exit (1)
status_notify ('%s CONNECT-XSERVER' % (greeter_id))
def show_message_cb (greeter, text, type):
status_notify ('%s SHOW-MESSAGE TEXT=\"%s\"' % (greeter_id, text))
def show_prompt_cb (greeter, text, type):
status_notify ('%s SHOW-PROMPT TEXT=\"%s\"' % (greeter_id, text))
def authentication_complete_cb (greeter):
if greeter.get_is_authenticated ():
is_authenticated = 'TRUE'
else:
is_authenticated = 'FALSE'
if greeter.get_authentication_user () is not None:
status_notify ('%s AUTHENTICATION-COMPLETE USERNAME=%s AUTHENTICATED=%s' % (greeter_id, greeter.get_authentication_user (), is_authenticated))
else:
status_notify ('%s AUTHENTICATION-COMPLETE AUTHENTICATED=%s' % (greeter_id, is_authenticated))
def autologin_timer_expired_cb (greeter):
status_notify ('%s AUTOLOGIN-TIMER-EXPIRED' % greeter_id)
greeter = LightDM.Greeter ()
greeter.connect ('show-message', show_message_cb)
greeter.connect ('show-prompt', show_prompt_cb)
greeter.connect ('authentication-complete', authentication_complete_cb)
greeter.connect ('autologin-timer-expired', autologin_timer_expired_cb)
status_notify ('%s CONNECT-TO-DAEMON' % greeter_id)
if not greeter.connect_sync ():
status_notify ('%s FAIL-CONNECT-DAEMON' % greeter_id)
exit (1)
status_notify ('%s CONNECTED-TO-DAEMON' % greeter_id)
if greeter.get_select_user_hint () is not None:
status_notify ('%s SELECT-USER-HINT USERNAME=%s' % (greeter_id, greeter.get_select_user_hint ()))
if greeter.get_lock_hint ():
status_notify ('%s LOCK-HINT' % greeter_id);
loop.run ()
|