diff options
author | Robert Ancell <robert.ancell@canonical.com> | 2013-11-26 16:18:23 +1300 |
---|---|---|
committer | Robert Ancell <robert.ancell@canonical.com> | 2013-11-26 16:18:23 +1300 |
commit | 29748799524a07574d2215982f0383eced9fe52f (patch) | |
tree | b1163b9e33eba2e10bc6cc6de4704250274bdbb1 | |
parent | 641d812add70b2e1bf1af255d4e5ecc786048f4c (diff) | |
download | lightdm-git-29748799524a07574d2215982f0383eced9fe52f.tar.gz |
Load configuration from /etc/lightdm/lightdm.conf.d
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/configuration.c | 27 | ||||
-rw-r--r-- | src/lightdm.c | 73 | ||||
-rw-r--r-- | tests/Makefile.am | 10 | ||||
-rw-r--r-- | tests/scripts/0-additional.conf | 2 | ||||
-rw-r--r-- | tests/scripts/1-additional.conf | 2 | ||||
-rw-r--r-- | tests/scripts/additional-config-priority.conf | 31 | ||||
-rw-r--r-- | tests/scripts/additional-config.conf | 30 | ||||
-rw-r--r-- | tests/scripts/additional-system-config-priority.conf | 31 | ||||
-rw-r--r-- | tests/scripts/additional-system-config.conf | 30 | ||||
-rw-r--r-- | tests/src/test-runner.c | 31 | ||||
-rwxr-xr-x | tests/test-additional-config | 2 | ||||
-rwxr-xr-x | tests/test-additional-config-priority | 2 | ||||
-rwxr-xr-x | tests/test-additional-system-config | 2 | ||||
-rwxr-xr-x | tests/test-additional-system-config-priority | 2 |
15 files changed, 267 insertions, 9 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index ba1e544e..dceb51a6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -86,6 +86,7 @@ lightdm_CFLAGS = \ -DRUN_DIR=\"$(localstatedir)/run/lightdm\" \ -DCACHE_DIR=\"$(localstatedir)/cache/lightdm\" \ -DXSESSIONS_DIR=\"$(datadir)/xsessions\" \ + -DSYSTEM_CONFIG_DIR=\"$(pkgdatadir)/lightdm.conf.d\" \ -DREMOTE_SESSIONS_DIR=\"$(pkgdatadir)/remote-sessions\" \ -DXGREETERS_DIR=\"$(datadir)/xgreeters\" diff --git a/src/configuration.c b/src/configuration.c index 4d2fca66..e3b15df8 100644 --- a/src/configuration.c +++ b/src/configuration.c @@ -31,7 +31,32 @@ config_get_instance (void) gboolean config_load_from_file (Configuration *config, const gchar *path, GError **error) { - return g_key_file_load_from_file (config->priv->key_file, path, G_KEY_FILE_NONE, error); + GKeyFile *key_file; + gchar **groups; + int i; + + key_file = g_key_file_new (); + if (!g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, error)) + return FALSE; + + groups = g_key_file_get_groups (key_file, NULL); + for (i = 0; groups[i]; i++) + { + gchar **keys; + int j; + + keys = g_key_file_get_keys (key_file, groups[i], NULL, error); + if (!keys) + break; + + for (j = 0; keys[j]; j++) + g_key_file_set_value (config->priv->key_file, groups[i], keys[j], g_key_file_get_value (key_file, groups[i], keys[j], NULL)); + + g_strfreev (keys); + } + g_strfreev (groups); + + return TRUE; } gchar ** diff --git a/src/lightdm.c b/src/lightdm.c index aa1b6b4e..4a3270b0 100644 --- a/src/lightdm.c +++ b/src/lightdm.c @@ -805,6 +805,55 @@ vnc_connection_cb (VNCServer *server, GSocket *connection) g_object_unref (seat); } +static int +compare_strings (gconstpointer a, gconstpointer b) +{ + return strcmp (a, b); +} + +static void +load_config_directory (const gchar *path, GList **messages) +{ + GDir *dir; + GList *files = NULL, *link; + GError *error = NULL; + + /* Find configuration files */ + dir = g_dir_open (path, 0, &error); + if (error && !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) + g_printerr ("Failed to open configuration directory %s: %s\n", path, error->message); + g_clear_error (&error); + if (dir) + { + const gchar *name; + while ((name = g_dir_read_name (dir))) + files = g_list_append (files, g_strdup (name)); + g_dir_close (dir); + } + + /* Sort alphabetically and load onto existing configuration */ + files = g_list_sort (files, compare_strings); + for (link = files; link; link = link->next) + { + gchar *filename = link->data; + gchar *conf_path; + + conf_path = g_build_filename (path, filename, NULL); + if (g_str_has_suffix (filename, ".conf")) + { + *messages = g_list_append (*messages, g_strdup_printf ("Loading configuration from %s", conf_path)); + config_load_from_file (config_get_instance (), conf_path, &error); + if (error && !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) + g_printerr ("Failed to load configuration from %s: %s\n", filename, error->message); + g_clear_error (&error); + } + else + g_debug ("Ignoring configuration file %s, it does not have .conf suffix", conf_path); + g_free (conf_path); + } + g_list_free_full (files, g_free); +} + int main (int argc, char **argv) { @@ -819,7 +868,7 @@ main (int argc, char **argv) gchar *xsessions_dir = NULL; gchar *remote_sessions_dir = NULL; gchar *xgreeters_dir = NULL; - gchar *config_dir; + gchar *config_dir, *config_d_dir = NULL; gchar *log_dir = NULL; gchar *run_dir = NULL; gchar *cache_dir = NULL; @@ -827,7 +876,8 @@ main (int argc, char **argv) gchar *default_run_dir = g_strdup (RUN_DIR); gchar *default_cache_dir = g_strdup (CACHE_DIR); gboolean show_version = FALSE; - GOptionEntry options[] = + GList *link, *messages = NULL; + GOptionEntry options[] = { { "config", 'c', 0, G_OPTION_ARG_STRING, &config_path, /* Help string for command line --config flag */ @@ -875,6 +925,8 @@ main (int argc, char **argv) #endif loop = g_main_loop_new (NULL, FALSE); + messages = g_list_append (messages, g_strdup_printf ("Starting Light Display Manager %s, UID=%i PID=%i", VERSION, getuid (), getpid ())); + g_signal_connect (process_get_current (), "got-signal", G_CALLBACK (signal_cb), NULL); option_context = g_option_context_new (/* Arguments and description for --help test */ @@ -909,6 +961,7 @@ main (int argc, char **argv) else { config_dir = g_strdup (CONFIG_DIR); + config_d_dir = g_build_filename (config_dir, "lightdm.conf.d", NULL); config_path = g_build_filename (config_dir, "lightdm.conf", NULL); } config_set_string (config_get_instance (), "LightDM", "config-directory", config_dir); @@ -972,7 +1025,12 @@ main (int argc, char **argv) default_cache_dir = g_build_filename (g_get_user_cache_dir (), "lightdm", "cache", NULL); } - /* Load config file */ + /* Load config file(s) */ + load_config_directory (SYSTEM_CONFIG_DIR, &messages); + if (config_d_dir) + load_config_directory (config_d_dir, &messages); + g_free (config_d_dir); + messages = g_list_append (messages, g_strdup_printf ("Loading configuration from %s", config_path)); if (!config_load_from_file (config_get_instance (), config_path, &error)) { gboolean is_empty; @@ -987,6 +1045,7 @@ main (int argc, char **argv) } } g_clear_error (&error); + g_free (config_path); /* Set default values */ if (!config_has_key (config_get_instance (), "LightDM", "start-default-seat")) @@ -1066,10 +1125,10 @@ main (int argc, char **argv) log_init (); - g_debug ("Starting Light Display Manager %s, UID=%i PID=%i", VERSION, getuid (), getpid ()); - - g_debug ("Loaded configuration from %s", config_path); - g_free (config_path); + /* Show queued messages once logging is complete */ + for (link = messages; link; link = link->next) + g_debug ("%s", (gchar *)link->data); + g_list_free_full (messages, g_free); g_debug ("Using D-Bus name %s", LIGHTDM_BUS_NAME); bus_id = g_bus_own_name (getuid () == 0 ? G_BUS_TYPE_SYSTEM : G_BUS_TYPE_SESSION, diff --git a/tests/Makefile.am b/tests/Makefile.am index cdb49f90..eb1675f6 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -11,6 +11,10 @@ TESTS = \ test-greeter-show-manual-login \ test-greeter-show-remote-login \ test-no-config \ + test-additional-config \ + test-additional-config-priority \ + test-additional-system-config \ + test-additional-system-config-priority \ test-headless \ test-autologin \ test-autologin-invalid-user \ @@ -193,6 +197,12 @@ EXTRA_DIST = \ data/xgreeters/test-qt-greeter.desktop \ data/xsessions/alternative.desktop \ data/xsessions/default.desktop \ + scripts/0-additional.conf \ + scripts/1-additional.conf \ + scripts/additional-config.conf \ + scripts/additional-config-priority.conf \ + scripts/additional-system-config.conf \ + scripts/additional-system-config-priority.conf \ scripts/autologin.conf \ scripts/autologin-guest.conf \ scripts/autologin-guest-fail-setup-script.conf \ diff --git a/tests/scripts/0-additional.conf b/tests/scripts/0-additional.conf new file mode 100644 index 00000000..16dd53c5 --- /dev/null +++ b/tests/scripts/0-additional.conf @@ -0,0 +1,2 @@ +[SeatDefaults] +autologin-user=have-password1 diff --git a/tests/scripts/1-additional.conf b/tests/scripts/1-additional.conf new file mode 100644 index 00000000..07fa3d93 --- /dev/null +++ b/tests/scripts/1-additional.conf @@ -0,0 +1,2 @@ +[SeatDefaults] +autologin-user=have-password2 diff --git a/tests/scripts/additional-config-priority.conf b/tests/scripts/additional-config-priority.conf new file mode 100644 index 00000000..b56dc4aa --- /dev/null +++ b/tests/scripts/additional-config-priority.conf @@ -0,0 +1,31 @@ +# +# Check LightDM runs with config.d configuration and the value from the lightdm.conf is used +# + +[test-runner-config] +additional-config=0-additional.conf + +[SeatDefaults] +autologin-user=have-password2 +user-session=default + +#?RUNNER DAEMON-START + +# X server starts +#?XSERVER-0 START VT=7 + +# Daemon connects when X server is ready +#?*XSERVER-0 INDICATE-READY +#?XSERVER-0 INDICATE-READY +#?XSERVER-0 ACCEPT-CONNECT + +# Session starts +#?SESSION-X-0 START XDG_SESSION_COOKIE=ck-cookie-x:0 USER=have-password2 +#?XSERVER-0 ACCEPT-CONNECT +#?SESSION-X-0 CONNECT-XSERVER + +# Cleanup +#?*STOP-DAEMON +#?SESSION-X-0 TERMINATE SIGNAL=15 +#?XSERVER-0 TERMINATE SIGNAL=15 +#?RUNNER DAEMON-EXIT STATUS=0 diff --git a/tests/scripts/additional-config.conf b/tests/scripts/additional-config.conf new file mode 100644 index 00000000..1a202dce --- /dev/null +++ b/tests/scripts/additional-config.conf @@ -0,0 +1,30 @@ +# +# Check LightDM runs with config.d configuration and the value from the last file is used +# + +[test-runner-config] +additional-config=0-additional.conf 1-additional.conf + +[SeatDefaults] +user-session=default + +#?RUNNER DAEMON-START + +# X server starts +#?XSERVER-0 START VT=7 + +# Daemon connects when X server is ready +#?*XSERVER-0 INDICATE-READY +#?XSERVER-0 INDICATE-READY +#?XSERVER-0 ACCEPT-CONNECT + +# Session starts +#?SESSION-X-0 START XDG_SESSION_COOKIE=ck-cookie-x:0 USER=have-password2 +#?XSERVER-0 ACCEPT-CONNECT +#?SESSION-X-0 CONNECT-XSERVER + +# Cleanup +#?*STOP-DAEMON +#?SESSION-X-0 TERMINATE SIGNAL=15 +#?XSERVER-0 TERMINATE SIGNAL=15 +#?RUNNER DAEMON-EXIT STATUS=0 diff --git a/tests/scripts/additional-system-config-priority.conf b/tests/scripts/additional-system-config-priority.conf new file mode 100644 index 00000000..f9e90780 --- /dev/null +++ b/tests/scripts/additional-system-config-priority.conf @@ -0,0 +1,31 @@ +# +# Check LightDM runs with system config.d configuration and the value from /etc is used +# + +[test-runner-config] +additional-system-config=0-additional.conf +additional-config=1-additional.conf + +[SeatDefaults] +user-session=default + +#?RUNNER DAEMON-START + +# X server starts +#?XSERVER-0 START VT=7 + +# Daemon connects when X server is ready +#?*XSERVER-0 INDICATE-READY +#?XSERVER-0 INDICATE-READY +#?XSERVER-0 ACCEPT-CONNECT + +# Session starts +#?SESSION-X-0 START XDG_SESSION_COOKIE=ck-cookie-x:0 USER=have-password2 +#?XSERVER-0 ACCEPT-CONNECT +#?SESSION-X-0 CONNECT-XSERVER + +# Cleanup +#?*STOP-DAEMON +#?SESSION-X-0 TERMINATE SIGNAL=15 +#?XSERVER-0 TERMINATE SIGNAL=15 +#?RUNNER DAEMON-EXIT STATUS=0 diff --git a/tests/scripts/additional-system-config.conf b/tests/scripts/additional-system-config.conf new file mode 100644 index 00000000..66db4cda --- /dev/null +++ b/tests/scripts/additional-system-config.conf @@ -0,0 +1,30 @@ +# +# Check LightDM runs with system-config.d configuration and the value from the last file is used +# + +[test-runner-config] +additional-system-config=0-additional.conf 1-additional.conf + +[SeatDefaults] +user-session=default + +#?RUNNER DAEMON-START + +# X server starts +#?XSERVER-0 START VT=7 + +# Daemon connects when X server is ready +#?*XSERVER-0 INDICATE-READY +#?XSERVER-0 INDICATE-READY +#?XSERVER-0 ACCEPT-CONNECT + +# Session starts +#?SESSION-X-0 START XDG_SESSION_COOKIE=ck-cookie-x:0 USER=have-password2 +#?XSERVER-0 ACCEPT-CONNECT +#?SESSION-X-0 CONNECT-XSERVER + +# Cleanup +#?*STOP-DAEMON +#?SESSION-X-0 TERMINATE SIGNAL=15 +#?XSERVER-0 TERMINATE SIGNAL=15 +#?RUNNER DAEMON-EXIT STATUS=0 diff --git a/tests/src/test-runner.c b/tests/src/test-runner.c index c2664df4..d66cb654 100644 --- a/tests/src/test-runner.c +++ b/tests/src/test-runner.c @@ -1805,7 +1805,8 @@ main (int argc, char **argv) { GMainLoop *loop; int i; - gchar *greeter = NULL, *script_name, *config_file, *path, *path1, *path2, *ld_preload, *ld_library_path, *home_dir; + gchar *greeter = NULL, *script_name, *config_file, *additional_system_config; + gchar *additional_config, *path, *path1, *path2, *ld_preload, *ld_library_path, *home_dir; GString *passwd_data, *group_data; GSource *status_source; gchar cwd[1024]; @@ -1939,6 +1940,34 @@ main (int argc, char **argv) if (system (g_strdup_printf ("cp %s %s/etc/lightdm/lightdm.conf", config_path, temp_dir))) perror ("Failed to copy configuration"); + additional_system_config = g_key_file_get_string (config, "test-runner-config", "additional-system-config", NULL); + if (additional_system_config) + { + gchar **files; + + g_mkdir_with_parents (g_strdup_printf ("%s/usr/share/lightdm/lightdm.conf.d", temp_dir), 0755); + + files = g_strsplit (additional_system_config, " ", -1); + for (i = 0; files[i]; i++) + if (system (g_strdup_printf ("cp %s/tests/scripts/%s %s/usr/share/lightdm/lightdm.conf.d", SRCDIR, files[i], temp_dir))) + perror ("Failed to copy configuration"); + g_strfreev (files); + } + + additional_config = g_key_file_get_string (config, "test-runner-config", "additional-config", NULL); + if (additional_config) + { + gchar **files; + + g_mkdir_with_parents (g_strdup_printf ("%s/etc/lightdm/lightdm.conf.d", temp_dir), 0755); + + files = g_strsplit (additional_config, " ", -1); + for (i = 0; files[i]; i++) + if (system (g_strdup_printf ("cp %s/tests/scripts/%s %s/etc/lightdm/lightdm.conf.d", SRCDIR, files[i], temp_dir))) + perror ("Failed to copy configuration"); + g_strfreev (files); + } + /* Always copy the script */ if (system (g_strdup_printf ("cp %s %s/script", config_path, temp_dir))) perror ("Failed to copy configuration"); diff --git a/tests/test-additional-config b/tests/test-additional-config new file mode 100755 index 00000000..61eecea5 --- /dev/null +++ b/tests/test-additional-config @@ -0,0 +1,2 @@ +#!/bin/sh +./src/dbus-env ./src/test-runner additional-config test-gobject-greeter diff --git a/tests/test-additional-config-priority b/tests/test-additional-config-priority new file mode 100755 index 00000000..91d96f4b --- /dev/null +++ b/tests/test-additional-config-priority @@ -0,0 +1,2 @@ +#!/bin/sh +./src/dbus-env ./src/test-runner additional-config-priority test-gobject-greeter diff --git a/tests/test-additional-system-config b/tests/test-additional-system-config new file mode 100755 index 00000000..ad84124d --- /dev/null +++ b/tests/test-additional-system-config @@ -0,0 +1,2 @@ +#!/bin/sh +./src/dbus-env ./src/test-runner additional-system-config test-gobject-greeter diff --git a/tests/test-additional-system-config-priority b/tests/test-additional-system-config-priority new file mode 100755 index 00000000..e8fd4b95 --- /dev/null +++ b/tests/test-additional-system-config-priority @@ -0,0 +1,2 @@ +#!/bin/sh +./src/dbus-env ./src/test-runner additional-system-config-priority test-gobject-greeter |