122
quit_cb (DBusGProxy *proxy, LdmGreeter *greeter)
124
g_signal_emit (G_OBJECT (greeter), signals[QUIT], 0);
126
read_int (LdmGreeter *greeter)
129
g_io_channel_read_chars (greeter->priv->from_server_channel, (gchar *) &value, sizeof (value), NULL, NULL);
134
write_int (LdmGreeter *greeter, guint32 value)
136
if (g_io_channel_write_chars (greeter->priv->to_server_channel, (const gchar *) &value, sizeof (value), NULL, NULL) != G_IO_STATUS_NORMAL)
137
g_warning ("Error writing to server");
141
read_string (LdmGreeter *greeter)
146
length = read_int (greeter);
147
value = g_malloc (sizeof (gchar *) * (length + 1));
148
g_io_channel_read_chars (greeter->priv->from_server_channel, value, length, NULL, NULL);
149
value[length] = '\0';
155
write_string (LdmGreeter *greeter, const gchar *value)
157
write_int (greeter, strlen (value));
158
g_io_channel_write_chars (greeter->priv->to_server_channel, value, -1, NULL, NULL);
162
flush (LdmGreeter *greeter)
164
g_io_channel_flush (greeter->priv->to_server_channel, NULL);
168
handle_prompt_authentication (LdmGreeter *greeter)
172
n_messages = read_int (greeter);
173
g_debug ("Prompt user with %d message(s)", n_messages);
175
for (i = 0; i < n_messages; i++)
180
msg_style = read_int (greeter);
181
msg = read_string (greeter);
183
// FIXME: Should stop on prompts?
186
case PAM_PROMPT_ECHO_OFF:
187
case PAM_PROMPT_ECHO_ON:
188
g_signal_emit (G_OBJECT (greeter), signals[SHOW_PROMPT], 0, msg);
191
g_signal_emit (G_OBJECT (greeter), signals[SHOW_ERROR], 0, msg);
194
g_signal_emit (G_OBJECT (greeter), signals[SHOW_MESSAGE], 0, msg);
203
from_server_cb (GIOChannel *source, GIOCondition condition, gpointer data)
205
LdmGreeter *greeter = data;
206
int message, return_code;
208
message = read_int (greeter);
211
case GREETER_MESSAGE_CONNECTED:
212
greeter->priv->theme = read_string (greeter);
213
greeter->priv->default_layout = read_string (greeter);
214
greeter->priv->default_session = read_string (greeter);
215
greeter->priv->timed_user = read_string (greeter);
216
greeter->priv->login_delay = read_int (greeter);
218
g_debug ("Connected theme=%s default-layout=%s default-session=%s timed-user=%s login-delay=%d",
219
greeter->priv->theme,
220
greeter->priv->default_layout, greeter->priv->default_session,
221
greeter->priv->timed_user, greeter->priv->login_delay);
223
/* Set timeout for default login */
224
if (greeter->priv->timed_user[0] != '\0' && greeter->priv->login_delay > 0)
226
g_debug ("Logging in as %s in %d seconds", greeter->priv->timed_user, greeter->priv->login_delay);
227
greeter->priv->login_timeout = g_timeout_add (greeter->priv->login_delay * 1000, timed_login_cb, greeter);
229
g_signal_emit (G_OBJECT (greeter), signals[CONNECTED], 0);
231
case GREETER_MESSAGE_QUIT:
232
g_signal_emit (G_OBJECT (greeter), signals[QUIT], 0);
234
case GREETER_MESSAGE_PROMPT_AUTHENTICATION:
235
handle_prompt_authentication (greeter);
237
case GREETER_MESSAGE_END_AUTHENTICATION:
238
return_code = read_int (greeter);
239
g_debug ("Authentication complete with return code %d", return_code);
240
greeter->priv->is_authenticated = (return_code == 0);
241
if (!greeter->priv->is_authenticated)
243
g_free (greeter->priv->authentication_user);
244
greeter->priv->authentication_user = NULL;
246
g_signal_emit (G_OBJECT (greeter), signals[AUTHENTICATION_COMPLETE], 0);
249
g_warning ("Unknown message from server: %d", message);
160
288
if (!greeter->priv->lightdm_bus)
163
object = getenv ("LDM_DISPLAY");
166
g_warning ("No LDM_DISPLAY enviroment variable");
170
greeter->priv->display_proxy = dbus_g_proxy_new_for_name (greeter->priv->lightdm_bus,
171
"org.lightdm.LightDisplayManager",
173
"org.lightdm.LightDisplayManager.Greeter");
174
dbus_g_proxy_add_signal (greeter->priv->display_proxy, "QuitGreeter", G_TYPE_INVALID);
175
dbus_g_proxy_connect_signal (greeter->priv->display_proxy, "QuitGreeter", G_CALLBACK (quit_cb), greeter, NULL);
291
fd = getenv ("LDM_TO_SERVER_FD");
294
g_warning ("No LDM_TO_SERVER_FD environment variable");
297
greeter->priv->to_server_channel = g_io_channel_unix_new (atoi (fd));
298
g_io_channel_set_encoding (greeter->priv->to_server_channel, NULL, NULL);
300
fd = getenv ("LDM_FROM_SERVER_FD");
303
g_warning ("No LDM_FROM_SERVER_FD environment variable");
306
greeter->priv->from_server_channel = g_io_channel_unix_new (atoi (fd));
307
g_io_channel_set_encoding (greeter->priv->from_server_channel, NULL, NULL);
308
g_io_add_watch (greeter->priv->from_server_channel, G_IO_IN, from_server_cb, greeter);
176
310
greeter->priv->session_proxy = dbus_g_proxy_new_for_name (greeter->priv->lightdm_bus,
177
311
"org.lightdm.LightDisplayManager",
178
312
"/org/lightdm/LightDisplayManager/Session",
183
317
"org.lightdm.LightDisplayManager.Users");
185
319
g_debug ("Connecting to display manager...");
186
result = dbus_g_proxy_call (greeter->priv->display_proxy, "Connect", &error,
188
G_TYPE_STRING, &greeter->priv->theme,
189
G_TYPE_STRING, &greeter->priv->default_layout,
190
G_TYPE_STRING, &greeter->priv->default_session,
191
G_TYPE_STRING, &greeter->priv->timed_user,
192
G_TYPE_INT, &greeter->priv->login_delay,
196
g_debug ("Connected theme=%s default-layout=%s default-session=%s timed-user=%s login-delay=%d",
197
greeter->priv->theme,
198
greeter->priv->default_layout, greeter->priv->default_session,
199
greeter->priv->timed_user, greeter->priv->login_delay);
201
g_warning ("Failed to connect to display manager: %s", error->message);
202
g_clear_error (&error);
206
/* Set timeout for default login */
207
if (greeter->priv->timed_user[0] != '\0' && greeter->priv->login_delay > 0)
209
g_debug ("Logging in as %s in %d seconds", greeter->priv->timed_user, greeter->priv->login_delay);
210
greeter->priv->login_timeout = g_timeout_add (greeter->priv->login_delay * 1000, timed_login_cb, greeter);
320
write_int (greeter, GREETER_MESSAGE_CONNECT);
763
873
greeter->priv->login_timeout = 0;
766
#define TYPE_MESSAGE dbus_g_type_get_struct ("GValueArray", G_TYPE_INT, G_TYPE_STRING, G_TYPE_INVALID)
767
#define TYPE_MESSAGE_LIST dbus_g_type_get_collection ("GPtrArray", TYPE_MESSAGE)
770
auth_response_cb (DBusGProxy *proxy, DBusGProxyCall *call, gpointer userdata)
772
LdmGreeter *greeter = userdata;
774
GError *error = NULL;
779
result = dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INT, &return_code, TYPE_MESSAGE_LIST, &array, G_TYPE_INVALID);
781
g_warning ("Failed to complete StartAuthentication(): %s", error->message);
782
g_clear_error (&error);
787
g_debug ("Authentication continues with %d messages", array->len);
789
g_debug ("Authentication complete with return code %d", return_code);
791
for (i = 0; i < array->len; i++)
793
GValue value = { 0 };
797
g_value_init (&value, TYPE_MESSAGE);
798
g_value_set_static_boxed (&value, array->pdata[i]);
799
dbus_g_type_struct_get (&value, 0, &msg_style, 1, &msg, G_MAXUINT);
801
// FIXME: Should stop on prompts?
804
case PAM_PROMPT_ECHO_OFF:
805
case PAM_PROMPT_ECHO_ON:
806
g_signal_emit (G_OBJECT (greeter), signals[SHOW_PROMPT], 0, msg);
809
g_signal_emit (G_OBJECT (greeter), signals[SHOW_ERROR], 0, msg);
812
g_signal_emit (G_OBJECT (greeter), signals[SHOW_MESSAGE], 0, msg);
818
g_value_unset (&value);
823
greeter->priv->is_authenticated = (return_code == 0);
824
if (!greeter->priv->is_authenticated)
826
g_free (greeter->priv->authentication_user);
827
greeter->priv->authentication_user = NULL;
829
g_signal_emit (G_OBJECT (greeter), signals[AUTHENTICATION_COMPLETE], 0);
832
g_ptr_array_unref (array);
836
877
* ldm_greeter_start_authentication:
837
878
* @greeter: A #LdmGreeter
863
906
ldm_greeter_provide_secret (LdmGreeter *greeter, const gchar *secret)
867
908
g_return_if_fail (LDM_IS_GREETER (greeter));
868
909
g_return_if_fail (secret != NULL);
911
g_debug ("Providing secret to display manager");
912
write_int (greeter, GREETER_MESSAGE_CONTINUE_AUTHENTICATION);
870
913
// FIXME: Could be multiple secrets required
871
secrets = g_malloc (sizeof (char *) * 2);
872
secrets[0] = g_strdup (secret);
874
g_debug ("Providing secret to display manager");
875
dbus_g_proxy_begin_call (greeter->priv->display_proxy, "ContinueAuthentication", auth_response_cb, greeter, NULL, G_TYPE_STRV, secrets, G_TYPE_INVALID);
914
write_int (greeter, 1);
915
write_string (greeter, secret);
930
971
ldm_greeter_login (LdmGreeter *greeter, const gchar *username, const gchar *session, const gchar *language)
932
GError *error = NULL;
934
973
g_return_if_fail (LDM_IS_GREETER (greeter));
935
974
g_return_if_fail (username != NULL);
937
976
g_debug ("Logging in");
938
if (!dbus_g_proxy_call (greeter->priv->display_proxy, "Login", &error,
939
G_TYPE_STRING, username,
940
G_TYPE_STRING, session ? session : "",
941
G_TYPE_STRING, language ? language : "",
944
g_warning ("Failed to login: %s", error->message);
945
g_clear_error (&error);
977
write_int (greeter, GREETER_MESSAGE_LOGIN);
978
write_string (greeter, username);
979
write_string (greeter, session ? session : "");
980
write_string (greeter, language ? language : "");