]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blob - src/lightdm.c
Make PAM services configurable
[sojka/lightdm.git] / src / lightdm.c
1 /*
2  * Copyright (C) 2010-2011 Robert Ancell.
3  * Author: Robert Ancell <robert.ancell@canonical.com>
4  *
5  * This program is free software: you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License as published by the Free Software
7  * Foundation, either version 3 of the License, or (at your option) any later
8  * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
9  * license.
10  */
11
12 #include <config.h>
13
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include <sys/stat.h>
17 #include <glib.h>
18 #include <glib/gi18n.h>
19 #include <unistd.h>
20 #include <fcntl.h>
21 #include <sys/stat.h>
22 #include <errno.h>
23
24 #include "configuration.h"
25 #include "display-manager.h"
26 #include "xdmcp-server.h"
27 #include "vnc-server.h"
28 #include "seat-xdmcp-session.h"
29 #include "seat-xvnc.h"
30 #include "x-server.h"
31 #include "process.h"
32 #include "session-child.h"
33 #include "shared-data-manager.h"
34 #include "user-list.h"
35
36 static gchar *config_path = NULL;
37 static GMainLoop *loop = NULL;
38 static GTimer *log_timer;
39 static int log_fd = -1;
40 static gboolean debug = FALSE;
41
42 static DisplayManager *display_manager = NULL;
43 static XDMCPServer *xdmcp_server = NULL;
44 static VNCServer *vnc_server = NULL;
45 static guint bus_id = 0;
46 static GDBusConnection *bus = NULL;
47 static guint reg_id = 0;
48 static GDBusNodeInfo *seat_info;
49 static GHashTable *seat_bus_entries = NULL;
50 static guint seat_index = 0;
51 static GDBusNodeInfo *session_info;
52 static GHashTable *session_bus_entries = NULL;
53 static guint session_index = 0;
54 static gint exit_code = EXIT_SUCCESS;
55
56 typedef struct
57 {
58     gchar *path;
59     guint bus_id;
60 } SeatBusEntry;
61 typedef struct
62 {
63     gchar *path;
64     gchar *seat_path;
65     guint bus_id;
66 } SessionBusEntry;
67
68 #define LIGHTDM_BUS_NAME "org.freedesktop.DisplayManager"
69
70 static void
71 log_cb (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer data)
72 {
73     const gchar *prefix;
74     gchar *text;
75
76     switch (log_level & G_LOG_LEVEL_MASK)
77     {
78     case G_LOG_LEVEL_ERROR:
79         prefix = "ERROR:";
80         break;
81     case G_LOG_LEVEL_CRITICAL:
82         prefix = "CRITICAL:";
83         break;
84     case G_LOG_LEVEL_WARNING:
85         prefix = "WARNING:";
86         break;
87     case G_LOG_LEVEL_MESSAGE:
88         prefix = "MESSAGE:";
89         break;
90     case G_LOG_LEVEL_INFO:
91         prefix = "INFO:";
92         break;
93     case G_LOG_LEVEL_DEBUG:
94         prefix = "DEBUG:";
95         break;
96     default:
97         prefix = "LOG:";
98         break;
99     }
100
101     text = g_strdup_printf ("[%+.2fs] %s %s\n", g_timer_elapsed (log_timer, NULL), prefix, message);
102
103     /* Log everything to a file */
104     if (log_fd >= 0)
105     {
106         ssize_t n_written;
107         n_written = write (log_fd, text, strlen (text));
108         if (n_written < 0)
109             ; /* Check result so compiler doesn't warn about it */
110     }
111
112     /* Log to stderr if requested */
113     if (debug)
114         g_printerr ("%s", text);
115     else
116         g_log_default_handler (log_domain, log_level, message, data);
117
118     g_free (text);
119 }
120
121 static void
122 log_init (void)
123 {
124     gchar *log_dir, *path, *old_path;
125
126     log_timer = g_timer_new ();
127
128     /* Log to a file */
129     log_dir = config_get_string (config_get_instance (), "LightDM", "log-directory");
130     path = g_build_filename (log_dir, "lightdm.log", NULL);
131     g_free (log_dir);
132
133     /* Move old file out of the way */
134     old_path = g_strdup_printf ("%s.old", path);
135     rename (path, old_path);
136     g_free (old_path);
137
138     /* Create new file and log to it */
139     log_fd = open (path, O_WRONLY | O_CREAT | O_TRUNC, 0600);
140     fcntl (log_fd, F_SETFD, FD_CLOEXEC);
141     g_log_set_default_handler (log_cb, NULL);
142
143     g_debug ("Logging to %s", path);
144     g_free (path);
145 }
146
147 static void
148 set_seat_properties (Seat *seat, const gchar *config_section)
149 {
150     gchar **keys;
151     gint i;
152
153     keys = config_get_keys (config_get_instance (), "SeatDefaults");
154     for (i = 0; keys[i]; i++)
155     {
156         gchar *value = config_get_string (config_get_instance (), "SeatDefaults", keys[i]);
157         seat_set_property (seat, keys[i], value);
158         g_free (value);
159     }
160     g_strfreev (keys);
161
162     if (config_section)
163     {
164         keys = config_get_keys (config_get_instance (), config_section);
165         for (i = 0; keys[i]; i++)
166         {
167             gchar *value = config_get_string (config_get_instance (), config_section, keys[i]);
168             seat_set_property (seat, keys[i], value);
169             g_free (value);
170         }
171         g_strfreev (keys);
172     }
173 }
174
175 static void
176 signal_cb (Process *process, int signum)
177 {
178     g_debug ("Caught %s signal, shutting down", g_strsignal (signum));
179     display_manager_stop (display_manager);
180     // FIXME: Stop XDMCP server
181 }
182
183 static void
184 display_manager_stopped_cb (DisplayManager *display_manager)
185 {
186     g_debug ("Stopping daemon");
187     g_main_loop_quit (loop);
188 }
189
190 static void
191 display_manager_seat_removed_cb (DisplayManager *display_manager, Seat *seat)
192 {
193     gchar **types;
194     gchar **iter;
195     Seat *next_seat = NULL;
196     GString *next_types;
197
198     /* If we have fallback types registered for the seat, let's try them
199        before giving up. */
200     types = seat_get_string_list_property (seat, "type");
201     next_types = g_string_new ("");
202     for (iter = types; iter && *iter; iter++)
203     {
204         if (iter == types)
205             continue; // skip first one, that is our current seat type
206
207         if (!next_seat)
208         {
209             next_seat = seat_new (*iter);
210             g_string_assign (next_types, *iter);
211         }
212         else
213         {
214             // Build up list of types to try next time
215             g_string_append_c (next_types, ';');
216             g_string_append (next_types, *iter);
217         }
218     }
219     g_strfreev (types);
220
221     if (next_seat)
222     {
223         const gchar *seat_name;
224         gchar *config_section = NULL;
225
226         seat_name = seat_get_string_property (seat, "seat-name");
227         if (seat_name)
228             config_section = g_strdup_printf ("Seat:%s", seat_name);
229         set_seat_properties (next_seat, config_section);
230         g_free (config_section);
231
232         // We set this manually on default seat.  Let's port it over if needed.
233         if (seat_get_boolean_property (seat, "exit-on-failure"))
234             seat_set_property (next_seat, "exit-on-failure", "true");
235
236         seat_set_property (next_seat, "type", next_types->str);
237
238         display_manager_add_seat (display_manager, next_seat);
239         g_object_unref (next_seat);
240     }
241     else if (seat_get_boolean_property (seat, "exit-on-failure"))
242     {
243         g_debug ("Required seat has stopped");
244         exit_code = EXIT_FAILURE;
245         display_manager_stop (display_manager);
246     }
247
248     g_string_free (next_types, TRUE);
249 }
250
251 static GVariant *
252 get_seat_list (void)
253 {
254     GVariantBuilder builder;
255     GHashTableIter iter;
256     gpointer value;
257
258     g_variant_builder_init (&builder, G_VARIANT_TYPE ("ao"));
259     g_hash_table_iter_init (&iter, seat_bus_entries);
260     while (g_hash_table_iter_next (&iter, NULL, &value))
261     {
262         SeatBusEntry *entry = value;
263         g_variant_builder_add_value (&builder, g_variant_new_object_path (entry->path));
264     }
265
266     return g_variant_builder_end (&builder);
267 }
268
269 static GVariant *
270 get_session_list (const gchar *seat_path)
271 {
272     GVariantBuilder builder;
273     GHashTableIter iter;
274     gpointer value;
275
276     g_variant_builder_init (&builder, G_VARIANT_TYPE ("ao"));
277
278     g_hash_table_iter_init (&iter, session_bus_entries);
279     while (g_hash_table_iter_next (&iter, NULL, &value))
280     {
281         SessionBusEntry *entry = value;
282         if (seat_path == NULL || strcmp (entry->seat_path, seat_path) == 0)
283             g_variant_builder_add_value (&builder, g_variant_new_object_path (entry->path));
284     }
285
286     return g_variant_builder_end (&builder);
287 }
288
289 static GVariant *
290 handle_display_manager_get_property (GDBusConnection       *connection,
291                                      const gchar           *sender,
292                                      const gchar           *object_path,
293                                      const gchar           *interface_name,
294                                      const gchar           *property_name,
295                                      GError               **error,
296                                      gpointer               user_data)
297 {
298     if (g_strcmp0 (property_name, "Seats") == 0)
299         return get_seat_list ();
300     else if (g_strcmp0 (property_name, "Sessions") == 0)
301         return get_session_list (NULL);
302
303     return NULL;
304 }
305
306 static void
307 handle_display_manager_call (GDBusConnection       *connection,
308                              const gchar           *sender,
309                              const gchar           *object_path,
310                              const gchar           *interface_name,
311                              const gchar           *method_name,
312                              GVariant              *parameters,
313                              GDBusMethodInvocation *invocation,
314                              gpointer               user_data)
315 {
316     if (g_strcmp0 (method_name, "AddSeat") == 0)
317     {
318         gchar *type;
319         GVariantIter *property_iter;
320         gchar *name, *value;
321         Seat *seat;
322
323         if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(sa(ss))")))
324             return;
325
326         g_variant_get (parameters, "(&sa(ss))", &type, &property_iter);
327
328         g_debug ("Adding seat of type %s", type);
329
330         seat = seat_new (type);
331         if (seat)
332         {
333             set_seat_properties (seat, NULL);
334             while (g_variant_iter_loop (property_iter, "(&s&s)", &name, &value))
335                 seat_set_property (seat, name, value);
336         }
337         g_variant_iter_free (property_iter);
338
339         if (!seat)
340         {
341             // FIXME: Need to make proper error
342             g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Unable to create seat of type %s", type);
343             return;
344         }
345
346         if (display_manager_add_seat (display_manager, seat))
347         {
348             SeatBusEntry *entry;
349
350             entry = g_hash_table_lookup (seat_bus_entries, seat);
351             g_dbus_method_invocation_return_value (invocation, g_variant_new ("(o)", entry->path));
352         }
353         else// FIXME: Need to make proper error
354             g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Failed to start seat");
355         g_object_unref (seat);
356     }
357     else if (g_strcmp0 (method_name, "AddLocalXSeat") == 0)
358     {
359         gint display_number;
360         Seat *seat;
361
362         if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(i)")))
363             return;
364
365         g_variant_get (parameters, "(i)", &display_number);
366
367         g_debug ("Adding local X seat :%d", display_number);
368
369         seat = seat_new ("xremote");
370         if (seat)
371         {
372             gchar *display_number_string;
373
374             set_seat_properties (seat, NULL);
375             display_number_string = g_strdup_printf ("%d", display_number);
376             seat_set_property (seat, "xserver-display-number", display_number_string);
377             g_free (display_number_string);
378         }
379
380         if (!seat)
381         {
382             // FIXME: Need to make proper error
383             g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Unable to create local X seat");
384             return;
385         }
386
387         if (display_manager_add_seat (display_manager, seat))
388         {
389             SeatBusEntry *entry;
390
391             entry = g_hash_table_lookup (seat_bus_entries, seat);
392             g_dbus_method_invocation_return_value (invocation, g_variant_new ("(o)", entry->path));
393         }
394         else// FIXME: Need to make proper error
395             g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, G_DBUS_ERROR_FAILED, "Failed to start seat");
396         g_object_unref (seat);
397     }
398 }
399
400 static GVariant *
401 handle_seat_get_property (GDBusConnection       *connection,
402                           const gchar           *sender,
403                           const gchar           *object_path,
404                           const gchar           *interface_name,
405                           const gchar           *property_name,
406                           GError               **error,
407                           gpointer               user_data)
408 {
409     Seat *seat = user_data;
410
411     if (g_strcmp0 (property_name, "CanSwitch") == 0)
412         return g_variant_new_boolean (seat_get_can_switch (seat));
413     if (g_strcmp0 (property_name, "HasGuestAccount") == 0)
414         return g_variant_new_boolean (seat_get_allow_guest (seat));
415     else if (g_strcmp0 (property_name, "Sessions") == 0)
416     {
417         SeatBusEntry *entry;
418
419         entry = g_hash_table_lookup (seat_bus_entries, seat);
420         return get_session_list (entry->path);
421     }
422
423     return NULL;
424 }
425
426 static void
427 handle_seat_call (GDBusConnection       *connection,
428                   const gchar           *sender,
429                   const gchar           *object_path,
430                   const gchar           *interface_name,
431                   const gchar           *method_name,
432                   GVariant              *parameters,
433                   GDBusMethodInvocation *invocation,
434                   gpointer               user_data)
435 {
436     Seat *seat = user_data;
437
438     if (g_strcmp0 (method_name, "SwitchToGreeter") == 0)
439     {
440         if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("()")))
441             return;
442
443         seat_switch_to_greeter (seat);
444         g_dbus_method_invocation_return_value (invocation, NULL);
445     }
446     else if (g_strcmp0 (method_name, "SwitchToUser") == 0)
447     {
448         const gchar *username, *session_name;
449
450         if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(ss)")))
451             return;
452
453         g_variant_get (parameters, "(&s&s)", &username, &session_name);
454         if (strcmp (session_name, "") == 0)
455             session_name = NULL;
456
457         seat_switch_to_user (seat, username, session_name);
458         g_dbus_method_invocation_return_value (invocation, NULL);
459     }
460     else if (g_strcmp0 (method_name, "SwitchToGuest") == 0)
461     {
462         const gchar *session_name;
463
464         if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(s)")))
465             return;
466
467         g_variant_get (parameters, "(&s)", &session_name);
468         if (strcmp (session_name, "") == 0)
469             session_name = NULL;
470
471         seat_switch_to_guest (seat, session_name);
472         g_dbus_method_invocation_return_value (invocation, NULL);
473     }
474     else if (g_strcmp0 (method_name, "Lock") == 0)
475     {
476         /* FIXME: Should only allow locks if have a session on this seat */
477         seat_lock (seat, NULL);
478         g_dbus_method_invocation_return_value (invocation, NULL);
479     }
480 }
481
482 static Seat *
483 get_seat_for_session (Session *session)
484 {
485     GList *seat_link;
486
487     for (seat_link = display_manager_get_seats (display_manager); seat_link; seat_link = seat_link->next)
488     {
489         Seat *seat = seat_link->data;
490         GList *session_link;
491
492         for (session_link = seat_get_sessions (seat); session_link; session_link = session_link->next)
493         {
494             Session *s = session_link->data;
495
496             if (s == session)
497                 return seat;
498         }
499     }
500
501     return NULL;
502 }
503
504 static GVariant *
505 handle_session_get_property (GDBusConnection       *connection,
506                              const gchar           *sender,
507                              const gchar           *object_path,
508                              const gchar           *interface_name,
509                              const gchar           *property_name,
510                              GError               **error,
511                              gpointer               user_data)
512 {
513     Session *session = user_data;
514     SessionBusEntry *entry;
515
516     entry = g_hash_table_lookup (session_bus_entries, session);
517     if (g_strcmp0 (property_name, "Seat") == 0)
518         return g_variant_new_object_path (entry ? entry->seat_path : "");
519     else if (g_strcmp0 (property_name, "UserName") == 0)
520         return g_variant_new_string (session_get_username (session));
521
522     return NULL;
523 }
524
525 static void
526 handle_session_call (GDBusConnection       *connection,
527                      const gchar           *sender,
528                      const gchar           *object_path,
529                      const gchar           *interface_name,
530                      const gchar           *method_name,
531                      GVariant              *parameters,
532                      GDBusMethodInvocation *invocation,
533                      gpointer               user_data)
534 {
535     Session *session = user_data;
536
537     if (g_strcmp0 (method_name, "Lock") == 0)
538     {
539         Seat *seat;
540
541         seat = get_seat_for_session (session);
542         /* FIXME: Should only allow locks if have a session on this seat */
543         seat_lock (seat, session_get_username (session));
544         g_dbus_method_invocation_return_value (invocation, NULL);
545     }
546 }
547
548 static SeatBusEntry *
549 seat_bus_entry_new (const gchar *path)
550 {
551     SeatBusEntry *entry;
552
553     entry = g_malloc0 (sizeof (SeatBusEntry));
554     entry->path = g_strdup (path);
555
556     return entry;
557 }
558
559 static SessionBusEntry *
560 session_bus_entry_new (const gchar *path, const gchar *seat_path)
561 {
562     SessionBusEntry *entry;
563
564     entry = g_malloc0 (sizeof (SessionBusEntry));
565     entry->path = g_strdup (path);
566     entry->seat_path = g_strdup (seat_path);
567
568     return entry;
569 }
570
571 static void
572 emit_object_value_changed (GDBusConnection *bus, const gchar *path, const gchar *interface_name, const gchar *property_name, GVariant *property_value)
573 {
574     GVariantBuilder builder;
575     GError *error = NULL;
576
577     g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
578     g_variant_builder_add (&builder, "{sv}", property_name, property_value);
579
580     if (!g_dbus_connection_emit_signal (bus,
581                                         NULL,
582                                         path,
583                                         "org.freedesktop.DBus.Properties",
584                                         "PropertiesChanged",
585                                         g_variant_new ("(sa{sv}as)", interface_name, &builder, NULL),
586                                         &error))
587         g_warning ("Failed to emit PropertiesChanged signal: %s", error->message);
588     g_clear_error (&error); 
589 }
590
591 static void
592 emit_object_signal (GDBusConnection *bus, const gchar *path, const gchar *signal_name, const gchar *object_path)
593 {
594     GError *error = NULL;
595
596     if (!g_dbus_connection_emit_signal (bus,
597                                         NULL,
598                                         path,
599                                         "org.freedesktop.DisplayManager",
600                                         signal_name,
601                                         g_variant_new ("(o)", object_path),
602                                         &error))
603         g_warning ("Failed to emit %s signal on %s: %s", signal_name, path, error->message);
604     g_clear_error (&error); 
605 }
606
607 static void
608 seat_bus_entry_free (gpointer data)
609 {
610     SeatBusEntry *entry = data;
611
612     g_dbus_connection_unregister_object (bus, entry->bus_id);
613
614     emit_object_value_changed (bus, "/org/freedesktop/DisplayManager", "org.freedesktop.DisplayManager", "Seats", get_seat_list ());
615     emit_object_signal (bus, "/org/freedesktop/DisplayManager", "SeatRemoved", entry->path);
616
617     g_free (entry->path);
618     g_free (entry);
619 }
620
621 static void
622 session_bus_entry_free (gpointer data)
623 {
624     SessionBusEntry *entry = data;
625
626     g_dbus_connection_unregister_object (bus, entry->bus_id);
627
628     emit_object_value_changed (bus, "/org/freedesktop/DisplayManager", "org.freedesktop.DisplayManager", "Sessions", get_session_list (NULL));
629     emit_object_signal (bus, "/org/freedesktop/DisplayManager", "SessionRemoved", entry->path);
630
631     emit_object_value_changed (bus, entry->seat_path, "org.freedesktop.DisplayManager.Seat", "Sessions", get_session_list (entry->seat_path));
632     emit_object_signal (bus, entry->seat_path, "SessionRemoved", entry->path);
633
634     g_free (entry->path);
635     g_free (entry->seat_path);
636     g_free (entry);
637 }
638
639 static void
640 running_user_session_cb (Seat *seat, Session *session)
641 {
642     static const GDBusInterfaceVTable session_vtable =
643     {
644         handle_session_call,
645         handle_session_get_property
646     };
647     SeatBusEntry *seat_entry;
648     SessionBusEntry *session_entry;
649     gchar *path;
650     GError *error = NULL;
651
652     /* Set environment variables when session runs */
653     seat_entry = g_hash_table_lookup (seat_bus_entries, seat);
654     session_set_env (session, "XDG_SEAT_PATH", seat_entry->path);
655     path = g_strdup_printf ("/org/freedesktop/DisplayManager/Session%d", session_index);
656     session_index++;
657     session_set_env (session, "XDG_SESSION_PATH", path);
658     g_object_set_data_full (G_OBJECT (session), "XDG_SESSION_PATH", path, g_free);
659
660     seat_entry = g_hash_table_lookup (seat_bus_entries, seat);
661     session_entry = session_bus_entry_new (g_object_get_data (G_OBJECT (session), "XDG_SESSION_PATH"), seat_entry ? seat_entry->path : NULL);
662     g_hash_table_insert (session_bus_entries, g_object_ref (session), session_entry);
663
664     g_debug ("Registering session with bus path %s", session_entry->path);
665
666     session_entry->bus_id = g_dbus_connection_register_object (bus,
667                                                                session_entry->path,
668                                                                session_info->interfaces[0],
669                                                                &session_vtable,
670                                                                g_object_ref (session), g_object_unref,
671                                                                &error);
672     if (session_entry->bus_id == 0)
673         g_warning ("Failed to register user session: %s", error->message);
674     g_clear_error (&error);
675
676     emit_object_value_changed (bus, "/org/freedesktop/DisplayManager", "org.freedesktop.DisplayManager", "Sessions", get_session_list (NULL));
677     emit_object_signal (bus, "/org/freedesktop/DisplayManager", "SessionAdded", session_entry->path);
678
679     emit_object_value_changed (bus, seat_entry->path, "org.freedesktop.DisplayManager.Seat", "Sessions", get_session_list (session_entry->seat_path));
680     emit_object_signal (bus, seat_entry->path, "SessionAdded", session_entry->path);
681 }
682
683 static void
684 session_removed_cb (Seat *seat, Session *session)
685 {
686     g_signal_handlers_disconnect_matched (session, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, seat);
687     g_hash_table_remove (session_bus_entries, session);
688 }
689
690 static void
691 seat_added_cb (DisplayManager *display_manager, Seat *seat)
692 {
693     static const GDBusInterfaceVTable seat_vtable =
694     {
695         handle_seat_call,
696         handle_seat_get_property
697     };
698     gchar *path;
699     SeatBusEntry *entry;
700     GError *error = NULL;
701
702     path = g_strdup_printf ("/org/freedesktop/DisplayManager/Seat%d", seat_index);
703     seat_index++;
704
705     entry = seat_bus_entry_new (path);
706     g_free (path);
707     g_hash_table_insert (seat_bus_entries, g_object_ref (seat), entry);
708
709     g_debug ("Registering seat with bus path %s", entry->path);
710
711     entry->bus_id = g_dbus_connection_register_object (bus,
712                                                        entry->path,
713                                                        seat_info->interfaces[0],
714                                                        &seat_vtable,
715                                                        g_object_ref (seat), g_object_unref,
716                                                        &error);
717     if (entry->bus_id == 0)
718         g_warning ("Failed to register seat: %s", error->message);
719     g_clear_error (&error);
720
721     emit_object_value_changed (bus, "/org/freedesktop/DisplayManager", "org.freedesktop.DisplayManager", "Seats", get_seat_list ());
722     emit_object_signal (bus, "/org/freedesktop/DisplayManager", "SeatAdded", entry->path);
723
724     g_signal_connect (seat, "running-user-session", G_CALLBACK (running_user_session_cb), NULL);
725     g_signal_connect (seat, "session-removed", G_CALLBACK (session_removed_cb), NULL);
726 }
727
728 static void
729 seat_removed_cb (DisplayManager *display_manager, Seat *seat)
730 {
731     g_hash_table_remove (seat_bus_entries, seat);
732 }
733
734 static gboolean
735 xdmcp_session_cb (XDMCPServer *server, XDMCPSession *session)
736 {
737     SeatXDMCPSession *seat;
738     gboolean result;
739
740     seat = seat_xdmcp_session_new (session);
741     set_seat_properties (SEAT (seat), NULL);
742     result = display_manager_add_seat (display_manager, SEAT (seat));
743     g_object_unref (seat);
744
745     return result;
746 }
747
748 static void
749 vnc_connection_cb (VNCServer *server, GSocket *connection)
750 {
751     SeatXVNC *seat;
752
753     seat = seat_xvnc_new (connection);
754     set_seat_properties (SEAT (seat), NULL);
755     display_manager_add_seat (display_manager, SEAT (seat));
756     g_object_unref (seat);
757 }
758
759 static void
760 bus_acquired_cb (GDBusConnection *connection,
761                  const gchar     *name,
762                  gpointer         user_data)
763 {
764     const gchar *display_manager_interface =
765         "<node>"
766         "  <interface name='org.freedesktop.DisplayManager'>"
767         "    <property name='Seats' type='ao' access='read'/>"
768         "    <property name='Sessions' type='ao' access='read'/>"
769         "    <method name='AddSeat'>"
770         "      <arg name='type' direction='in' type='s'/>"
771         "      <arg name='properties' direction='in' type='a(ss)'/>"
772         "      <arg name='seat' direction='out' type='o'/>"
773         "    </method>"
774         "    <method name='AddLocalXSeat'>"
775         "      <arg name='display-number' direction='in' type='i'/>"
776         "      <arg name='seat' direction='out' type='o'/>"
777         "    </method>"
778         "    <signal name='SeatAdded'>"
779         "      <arg name='seat' type='o'/>"
780         "    </signal>"
781         "    <signal name='SeatRemoved'>"
782         "      <arg name='seat' type='o'/>"
783         "    </signal>"
784         "    <signal name='SessionAdded'>"
785         "      <arg name='session' type='o'/>"
786         "    </signal>"
787         "    <signal name='SessionRemoved'>"
788         "      <arg name='session' type='o'/>"
789         "    </signal>"
790         "  </interface>"
791         "</node>";
792     static const GDBusInterfaceVTable display_manager_vtable =
793     {
794         handle_display_manager_call,
795         handle_display_manager_get_property
796     };
797     const gchar *seat_interface =
798         "<node>"
799         "  <interface name='org.freedesktop.DisplayManager.Seat'>"
800         "    <property name='CanSwitch' type='b' access='read'/>"
801         "    <property name='HasGuestAccount' type='b' access='read'/>"
802         "    <property name='Sessions' type='ao' access='read'/>"
803         "    <method name='SwitchToGreeter'/>"
804         "    <method name='SwitchToUser'>"
805         "      <arg name='username' direction='in' type='s'/>"
806         "      <arg name='session-name' direction='in' type='s'/>"
807         "    </method>"
808         "    <method name='SwitchToGuest'>"
809         "      <arg name='session-name' direction='in' type='s'/>"
810         "    </method>"
811         "    <method name='Lock'/>"
812         "    <signal name='SessionAdded'>"
813         "      <arg name='session' type='o'/>"
814         "    </signal>"
815         "    <signal name='SessionRemoved'>"
816         "      <arg name='session' type='o'/>"
817         "    </signal>"
818         "  </interface>"
819         "</node>";
820     const gchar *session_interface =
821         "<node>"
822         "  <interface name='org.freedesktop.DisplayManager.Session'>"
823         "    <property name='Seat' type='o' access='read'/>"
824         "    <property name='UserName' type='s' access='read'/>"
825         "    <method name='Lock'/>"
826         "  </interface>"
827         "</node>";
828     GDBusNodeInfo *display_manager_info;
829     GList *link;
830     GError *error = NULL;
831
832     g_debug ("Acquired bus name %s", name);
833
834     bus = connection;
835
836     display_manager_info = g_dbus_node_info_new_for_xml (display_manager_interface, NULL);
837     g_assert (display_manager_info != NULL);
838     seat_info = g_dbus_node_info_new_for_xml (seat_interface, NULL);
839     g_assert (seat_info != NULL);
840     session_info = g_dbus_node_info_new_for_xml (session_interface, NULL);
841     g_assert (session_info != NULL);
842
843     reg_id = g_dbus_connection_register_object (connection,
844                                                 "/org/freedesktop/DisplayManager",
845                                                 display_manager_info->interfaces[0],
846                                                 &display_manager_vtable,
847                                                 NULL, NULL,
848                                                 &error);
849     if (reg_id == 0)
850         g_warning ("Failed to register display manager: %s", error->message);
851     g_clear_error (&error);
852     g_dbus_node_info_unref (display_manager_info);
853
854     seat_bus_entries = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, seat_bus_entry_free);
855     session_bus_entries = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, session_bus_entry_free);
856
857     g_signal_connect (display_manager, "seat-added", G_CALLBACK (seat_added_cb), NULL);
858     g_signal_connect (display_manager, "seat-removed", G_CALLBACK (seat_removed_cb), NULL);
859     for (link = display_manager_get_seats (display_manager); link; link = link->next)
860         seat_added_cb (display_manager, (Seat *) link->data);
861
862     display_manager_start (display_manager);
863
864     /* Start the XDMCP server */
865     if (config_get_boolean (config_get_instance (), "XDMCPServer", "enabled"))
866     {
867         gchar *key_name, *key = NULL;
868
869         xdmcp_server = xdmcp_server_new ();
870         if (config_has_key (config_get_instance (), "XDMCPServer", "port"))
871         {
872             gint port;
873             port = config_get_integer (config_get_instance (), "XDMCPServer", "port");
874             if (port > 0)
875                 xdmcp_server_set_port (xdmcp_server, port);
876         }
877         g_signal_connect (xdmcp_server, "new-session", G_CALLBACK (xdmcp_session_cb), NULL);
878
879         key_name = config_get_string (config_get_instance (), "XDMCPServer", "key");
880         if (key_name)
881         {
882             gchar *dir, *path;
883             GKeyFile *keys;
884             gboolean result;
885             GError *error = NULL;
886
887             dir = config_get_string (config_get_instance (), "LightDM", "config-directory");
888             path = g_build_filename (dir, "keys.conf", NULL);
889             g_free (dir);
890
891             keys = g_key_file_new ();
892             result = g_key_file_load_from_file (keys, path, G_KEY_FILE_NONE, &error);
893             if (error)
894                 g_debug ("Error getting key %s", error->message);
895             g_clear_error (&error);
896
897             if (result)
898             {
899                 if (g_key_file_has_key (keys, "keyring", key_name, NULL))
900                     key = g_key_file_get_string (keys, "keyring", key_name, NULL);
901                 else
902                     g_debug ("Key %s not defined", key_name);
903             }
904             g_free (path);
905             g_key_file_free (keys);
906         }
907         if (key)
908             xdmcp_server_set_key (xdmcp_server, key);
909         g_free (key_name);
910         g_free (key);
911
912         g_debug ("Starting XDMCP server on UDP/IP port %d", xdmcp_server_get_port (xdmcp_server));
913         xdmcp_server_start (xdmcp_server);
914     }
915
916     /* Start the VNC server */
917     if (config_get_boolean (config_get_instance (), "VNCServer", "enabled"))
918     {
919         gchar *path;
920
921         path = g_find_program_in_path ("Xvnc");
922         if (path)
923         {
924             vnc_server = vnc_server_new ();
925             if (config_has_key (config_get_instance (), "VNCServer", "port"))
926             {
927                 gint port;
928                 port = config_get_integer (config_get_instance (), "VNCServer", "port");
929                 if (port > 0)
930                     vnc_server_set_port (vnc_server, port);
931             }
932             g_signal_connect (vnc_server, "new-connection", G_CALLBACK (vnc_connection_cb), NULL);
933
934             g_debug ("Starting VNC server on TCP/IP port %d", vnc_server_get_port (vnc_server));
935             vnc_server_start (vnc_server);
936
937             g_free (path);
938         }
939         else
940             g_warning ("Can't start VNC server, Xvnc is not in the path");
941     }
942 }
943
944 static void
945 name_lost_cb (GDBusConnection *connection,
946               const gchar *name,
947               gpointer user_data)
948 {
949     if (connection)
950         g_printerr ("Failed to use bus name " LIGHTDM_BUS_NAME ", do you have appropriate permissions?\n");
951     else
952         g_printerr ("Failed to get D-Bus connection\n");
953
954     exit (EXIT_FAILURE);
955 }
956
957 int
958 main (int argc, char **argv)
959 {
960     FILE *pid_file;
961     GOptionContext *option_context;
962     gboolean result;
963     gchar **groups, **i, *dir;
964     gint n_seats = 0;
965     gboolean test_mode = FALSE;
966     gchar *pid_path = "/var/run/lightdm.pid";
967     gchar *log_dir = NULL;
968     gchar *run_dir = NULL;
969     gchar *cache_dir = NULL;
970     gchar *default_log_dir = g_strdup (LOG_DIR);
971     gchar *default_run_dir = g_strdup (RUN_DIR);
972     gchar *default_cache_dir = g_strdup (CACHE_DIR);
973     gboolean show_version = FALSE;
974     GList *link, *messages = NULL;
975     GOptionEntry options[] =
976     {
977         { "config", 'c', 0, G_OPTION_ARG_STRING, &config_path,
978           /* Help string for command line --config flag */
979           N_("Use configuration file"), "FILE" },
980         { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug,
981           /* Help string for command line --debug flag */
982           N_("Print debugging messages"), NULL },
983         { "test-mode", 0, 0, G_OPTION_ARG_NONE, &test_mode,
984           /* Help string for command line --test-mode flag */
985           N_("Run as unprivileged user, skipping things that require root access"), NULL },
986         { "pid-file", 0, 0, G_OPTION_ARG_STRING, &pid_path,
987           /* Help string for command line --pid-file flag */
988           N_("File to write PID into"), "FILE" },
989         { "log-dir", 0, 0, G_OPTION_ARG_STRING, &log_dir,
990           /* Help string for command line --log-dir flag */
991           N_("Directory to write logs to"), "DIRECTORY" },
992         { "run-dir", 0, 0, G_OPTION_ARG_STRING, &run_dir,
993           /* Help string for command line --run-dir flag */
994           N_("Directory to store running state"), "DIRECTORY" },
995         { "cache-dir", 0, 0, G_OPTION_ARG_STRING, &cache_dir,
996           /* Help string for command line --cache-dir flag */
997           N_("Directory to cache information"), "DIRECTORY" },
998         { "version", 'v', 0, G_OPTION_ARG_NONE, &show_version,
999           /* Help string for command line --version flag */
1000           N_("Show release version"), NULL },
1001         { NULL }
1002     };
1003     GError *error = NULL;
1004
1005     /* When lightdm starts sessions it needs to run itself in a new mode */
1006     if (argc >= 2 && strcmp (argv[1], "--session-child") == 0)
1007         return session_child_run (argc, argv);
1008
1009 #if !defined(GLIB_VERSION_2_36)
1010     g_type_init ();
1011 #endif
1012     loop = g_main_loop_new (NULL, FALSE);
1013
1014     messages = g_list_append (messages, g_strdup_printf ("Starting Light Display Manager %s, UID=%i PID=%i", VERSION, getuid (), getpid ()));
1015
1016     g_signal_connect (process_get_current (), "got-signal", G_CALLBACK (signal_cb), NULL);
1017
1018     option_context = g_option_context_new (/* Arguments and description for --help test */
1019                                            _("- Display Manager"));
1020     g_option_context_add_main_entries (option_context, options, GETTEXT_PACKAGE);
1021     result = g_option_context_parse (option_context, &argc, &argv, &error);
1022     if (error)
1023         g_printerr ("%s\n", error->message);
1024     g_clear_error (&error);
1025     g_option_context_free (option_context);
1026     if (!result)
1027     {
1028         g_printerr (/* Text printed out when an unknown command-line argument provided */
1029                     _("Run '%s --help' to see a full list of available command line options."), argv[0]);
1030         g_printerr ("\n");
1031         return EXIT_FAILURE;
1032     }
1033
1034     if (show_version)
1035     {
1036         /* NOTE: Is not translated so can be easily parsed */
1037         g_printerr ("lightdm %s\n", VERSION);
1038         return EXIT_SUCCESS;
1039     }
1040
1041     if (!test_mode && getuid () != 0)
1042     {
1043         g_printerr ("Only root can run Light Display Manager.  To run as a regular user for testing run with the --test-mode flag.\n");
1044         return EXIT_FAILURE;
1045     }
1046
1047     /* If running inside an X server use Xephyr for display */
1048     if (getenv ("DISPLAY") && getuid () != 0)
1049     {
1050         gchar *x_server_path;
1051
1052         x_server_path = g_find_program_in_path ("Xephyr");
1053         if (!x_server_path)
1054         {
1055             g_printerr ("Running inside an X server requires Xephyr to be installed but it cannot be found.  Please install it or update your PATH environment variable.\n");
1056             return EXIT_FAILURE;
1057         }
1058         g_free (x_server_path);
1059     }
1060
1061     /* Make sure the system binary directory (where the greeters are installed) is in the path */
1062     if (test_mode)
1063     {
1064         const gchar *path = g_getenv ("PATH");
1065         gchar *new_path;
1066
1067         if (path)
1068             new_path = g_strdup_printf ("%s:%s", path, SBIN_DIR);
1069         else
1070             new_path = g_strdup (SBIN_DIR);
1071         g_setenv ("PATH", new_path, TRUE);
1072         g_free (new_path);
1073     }
1074
1075     /* Write PID file */
1076     pid_file = fopen (pid_path, "w");
1077     if (pid_file)
1078     {
1079         fprintf (pid_file, "%d\n", getpid ());
1080         fclose (pid_file);
1081     }
1082
1083     /* If not running as root write output to directories we control */
1084     if (getuid () != 0)
1085     {
1086         g_free (default_log_dir);
1087         default_log_dir = g_build_filename (g_get_user_cache_dir (), "lightdm", "log", NULL);
1088         g_free (default_run_dir);
1089         default_run_dir = g_build_filename (g_get_user_cache_dir (), "lightdm", "run", NULL);
1090         g_free (default_cache_dir);
1091         default_cache_dir = g_build_filename (g_get_user_cache_dir (), "lightdm", "cache", NULL);
1092     }
1093
1094     /* Load config file(s) */
1095     if (!config_load_from_standard_locations (config_get_instance (), config_path, &messages))
1096         exit (EXIT_FAILURE);
1097     g_free (config_path);
1098
1099     /* Set default values */
1100     if (!config_has_key (config_get_instance (), "LightDM", "start-default-seat"))
1101         config_set_boolean (config_get_instance (), "LightDM", "start-default-seat", TRUE);
1102     if (!config_has_key (config_get_instance (), "LightDM", "minimum-vt"))
1103         config_set_integer (config_get_instance (), "LightDM", "minimum-vt", 7);
1104     if (!config_has_key (config_get_instance (), "LightDM", "guest-account-script"))
1105         config_set_string (config_get_instance (), "LightDM", "guest-account-script", "guest-account");
1106     if (!config_has_key (config_get_instance (), "LightDM", "greeter-user"))
1107         config_set_string (config_get_instance (), "LightDM", "greeter-user", GREETER_USER);
1108     if (!config_has_key (config_get_instance (), "LightDM", "lock-memory"))
1109         config_set_boolean (config_get_instance (), "LightDM", "lock-memory", TRUE);
1110     if (!config_has_key (config_get_instance (), "SeatDefaults", "type"))
1111         config_set_string (config_get_instance (), "SeatDefaults", "type", "xlocal");
1112     if (!config_has_key (config_get_instance (), "SeatDefaults", "pam-service"))
1113         config_set_string (config_get_instance (), "SeatDefaults", "pam-service", "lightdm");
1114     if (!config_has_key (config_get_instance (), "SeatDefaults", "pam-autologin-service"))
1115         config_set_string (config_get_instance (), "SeatDefaults", "pam-autologin-service", "lightdm-autologin");
1116     if (!config_has_key (config_get_instance (), "SeatDefaults", "pam-greeter-service"))
1117         config_set_string (config_get_instance (), "SeatDefaults", "pam-greeter-service", "lightdm-greeter");
1118     if (!config_has_key (config_get_instance (), "SeatDefaults", "xserver-command"))
1119         config_set_string (config_get_instance (), "SeatDefaults", "xserver-command", "X");
1120     if (!config_has_key (config_get_instance (), "SeatDefaults", "xserver-share"))
1121         config_set_boolean (config_get_instance (), "SeatDefaults", "xserver-share", TRUE);
1122     if (!config_has_key (config_get_instance (), "SeatDefaults", "unity-compositor-command"))
1123         config_set_string (config_get_instance (), "SeatDefaults", "unity-compositor-command", "unity-system-compositor");
1124     if (!config_has_key (config_get_instance (), "SeatDefaults", "start-session"))
1125         config_set_boolean (config_get_instance (), "SeatDefaults", "start-session", TRUE);
1126     if (!config_has_key (config_get_instance (), "SeatDefaults", "allow-guest"))
1127         config_set_boolean (config_get_instance (), "SeatDefaults", "allow-guest", TRUE);
1128     if (!config_has_key (config_get_instance (), "SeatDefaults", "greeter-allow-guest"))
1129         config_set_boolean (config_get_instance (), "SeatDefaults", "greeter-allow-guest", TRUE);
1130     if (!config_has_key (config_get_instance (), "SeatDefaults", "greeter-show-remote-login"))
1131         config_set_boolean (config_get_instance (), "SeatDefaults", "greeter-show-remote-login", TRUE);
1132     if (!config_has_key (config_get_instance (), "SeatDefaults", "greeter-session"))
1133         config_set_string (config_get_instance (), "SeatDefaults", "greeter-session", GREETER_SESSION);
1134     if (!config_has_key (config_get_instance (), "SeatDefaults", "user-session"))
1135         config_set_string (config_get_instance (), "SeatDefaults", "user-session", USER_SESSION);
1136     if (!config_has_key (config_get_instance (), "SeatDefaults", "session-wrapper"))
1137         config_set_string (config_get_instance (), "SeatDefaults", "session-wrapper", "lightdm-session");
1138     if (!config_has_key (config_get_instance (), "LightDM", "log-directory"))
1139         config_set_string (config_get_instance (), "LightDM", "log-directory", default_log_dir);
1140     g_free (default_log_dir);
1141     if (!config_has_key (config_get_instance (), "LightDM", "run-directory"))
1142         config_set_string (config_get_instance (), "LightDM", "run-directory", default_run_dir);
1143     g_free (default_run_dir);
1144     if (!config_has_key (config_get_instance (), "LightDM", "cache-directory"))
1145         config_set_string (config_get_instance (), "LightDM", "cache-directory", default_cache_dir);
1146     g_free (default_cache_dir);
1147     if (!config_has_key (config_get_instance (), "LightDM", "sessions-directory"))
1148         config_set_string (config_get_instance (), "LightDM", "sessions-directory", SESSIONS_DIR);
1149     if (!config_has_key (config_get_instance (), "LightDM", "remote-sessions-directory"))
1150         config_set_string (config_get_instance (), "LightDM", "remote-sessions-directory", REMOTE_SESSIONS_DIR);
1151     if (!config_has_key (config_get_instance (), "LightDM", "greeters-directory"))
1152         config_set_string (config_get_instance (), "LightDM", "greeters-directory", GREETERS_DIR);
1153
1154     /* Override defaults */
1155     if (log_dir)
1156         config_set_string (config_get_instance (), "LightDM", "log-directory", log_dir);
1157     g_free (log_dir);
1158     if (run_dir)
1159         config_set_string (config_get_instance (), "LightDM", "run-directory", run_dir);
1160     g_free (run_dir);
1161     if (cache_dir)
1162         config_set_string (config_get_instance (), "LightDM", "cache-directory", cache_dir);
1163     g_free (cache_dir);
1164
1165     /* Create run and cache directories */
1166     dir = config_get_string (config_get_instance (), "LightDM", "log-directory");
1167     if (g_mkdir_with_parents (dir, S_IRWXU | S_IXGRP | S_IXOTH) < 0)
1168         g_warning ("Failed to make log directory %s: %s", dir, strerror (errno));
1169     g_free (dir);
1170     dir = config_get_string (config_get_instance (), "LightDM", "run-directory");
1171     if (g_mkdir_with_parents (dir, S_IRWXU | S_IXGRP | S_IXOTH) < 0)
1172         g_warning ("Failed to make run directory %s: %s", dir, strerror (errno));
1173     g_free (dir);
1174     dir = config_get_string (config_get_instance (), "LightDM", "cache-directory");
1175     if (g_mkdir_with_parents (dir, S_IRWXU | S_IXGRP | S_IXOTH) < 0)
1176         g_warning ("Failed to make cache directory %s: %s", dir, strerror (errno));
1177     g_free (dir);
1178
1179     log_init ();
1180
1181     /* Show queued messages once logging is complete */
1182     for (link = messages; link; link = link->next)
1183         g_debug ("%s", (gchar *)link->data);
1184     g_list_free_full (messages, g_free);
1185
1186     g_debug ("Using D-Bus name %s", LIGHTDM_BUS_NAME);
1187     bus_id = g_bus_own_name (getuid () == 0 ? G_BUS_TYPE_SYSTEM : G_BUS_TYPE_SESSION,
1188                              LIGHTDM_BUS_NAME,
1189                              G_BUS_NAME_OWNER_FLAGS_NONE,
1190                              bus_acquired_cb,
1191                              NULL,
1192                              name_lost_cb,
1193                              NULL,
1194                              NULL);
1195
1196     if (getuid () != 0)
1197         g_debug ("Running in user mode");
1198     if (getenv ("DISPLAY"))
1199         g_debug ("Using Xephyr for X servers");
1200
1201     display_manager = display_manager_new ();
1202     g_signal_connect (display_manager, "stopped", G_CALLBACK (display_manager_stopped_cb), NULL);
1203     g_signal_connect (display_manager, "seat-removed", G_CALLBACK (display_manager_seat_removed_cb), NULL);
1204
1205     shared_data_manager_start (shared_data_manager_get_instance ());
1206
1207     /* Load the static display entries */
1208     groups = config_get_groups (config_get_instance ());
1209     for (i = groups; *i; i++)
1210     {
1211         gchar *config_section = *i;
1212         gchar **types;
1213         gchar **type;
1214         Seat *seat = NULL;
1215         const gchar *const seatpfx = "Seat:";
1216
1217         if (!g_str_has_prefix (config_section, seatpfx))
1218             continue;
1219
1220         g_debug ("Loading seat %s", config_section);
1221         types = config_get_string_list (config_get_instance (), config_section, "type");
1222         if (!types)
1223             types = config_get_string_list (config_get_instance (), "SeatDefaults", "type");
1224         for (type = types; type && *type; type++)
1225         {
1226             seat = seat_new (*type);
1227             if (seat)
1228                 break;
1229         }
1230         g_strfreev (types);
1231         if (seat)
1232         {
1233             const gsize seatpfxlen = strlen(seatpfx);
1234             gchar *seatname = config_section + seatpfxlen;
1235
1236             seat_set_property (seat, "seat-name", seatname);
1237
1238             set_seat_properties (seat, config_section);
1239             display_manager_add_seat (display_manager, seat);
1240             g_object_unref (seat);
1241             n_seats++;
1242         }
1243         else
1244             g_warning ("Failed to create seat %s", config_section);
1245     }
1246     g_strfreev (groups);
1247
1248     /* If no seats start a default one */
1249     if (n_seats == 0 && config_get_boolean (config_get_instance (), "LightDM", "start-default-seat"))
1250     {
1251         gchar **types;
1252         gchar **type;
1253         Seat *seat = NULL;
1254
1255         g_debug ("Adding default seat");
1256
1257         types = config_get_string_list (config_get_instance (), "SeatDefaults", "type");
1258         for (type = types; type && *type; type++)
1259         {
1260             seat = seat_new (*type);
1261             if (seat)
1262                 break;
1263         }
1264         g_strfreev (types);
1265         if (seat)
1266         {
1267             set_seat_properties (seat, NULL);
1268             seat_set_property (seat, "exit-on-failure", "true");
1269             if (!display_manager_add_seat (display_manager, seat))
1270                 return EXIT_FAILURE;
1271             g_object_unref (seat);
1272         }
1273         else
1274         {
1275             g_warning ("Failed to create default seat");
1276             return EXIT_FAILURE;
1277         }
1278     }
1279
1280     g_main_loop_run (loop);
1281
1282     /* Clean up shared data manager */
1283     shared_data_manager_cleanup ();
1284
1285     /* Clean up user list */
1286     common_user_list_cleanup ();
1287
1288     /* Clean up display manager */
1289     g_object_unref (display_manager);
1290     display_manager = NULL;
1291
1292     /* Remove D-Bus interface */
1293     g_dbus_connection_unregister_object (bus, reg_id);
1294     g_bus_unown_name (bus_id);
1295     if (seat_bus_entries)
1296         g_hash_table_unref (seat_bus_entries);
1297     if (session_bus_entries)
1298         g_hash_table_unref (session_bus_entries);
1299
1300     g_debug ("Exiting with return value %d", exit_code);
1301     return exit_code;
1302 }