Skip to content

Commit 6877dd6

Browse files
committed
Load configuration from /etc/lightdm/lightdm.conf.d
1 parent 55410b4 commit 6877dd6

File tree

9 files changed

+154
-8
lines changed

9 files changed

+154
-8
lines changed

src/configuration.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,32 @@ config_get_instance (void)
3131
gboolean
3232
config_load_from_file (Configuration *config, const gchar *path, GError **error)
3333
{
34-
return g_key_file_load_from_file (config->priv->key_file, path, G_KEY_FILE_NONE, error);
34+
GKeyFile *key_file;
35+
gchar **groups;
36+
int i;
37+
38+
key_file = g_key_file_new ();
39+
if (!g_key_file_load_from_file (key_file, path, G_KEY_FILE_NONE, error))
40+
return FALSE;
41+
42+
groups = g_key_file_get_groups (key_file, NULL);
43+
for (i = 0; groups[i]; i++)
44+
{
45+
gchar **keys;
46+
int j;
47+
48+
keys = g_key_file_get_keys (key_file, groups[i], NULL, error);
49+
if (!keys)
50+
break;
51+
52+
for (j = 0; keys[j]; j++)
53+
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));
54+
55+
g_strfreev (keys);
56+
}
57+
g_strfreev (groups);
58+
59+
return TRUE;
3560
}
3661

3762
gchar **

src/lightdm.c

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,12 @@ vnc_connection_cb (VNCServer *server, GSocket *connection)
788788
g_object_unref (seat);
789789
}
790790

791+
static int
792+
compare_strings (gconstpointer a, gconstpointer b)
793+
{
794+
return strcmp (a, b);
795+
}
796+
791797
int
792798
main (int argc, char **argv)
793799
{
@@ -802,14 +808,15 @@ main (int argc, char **argv)
802808
gchar *xsessions_dir = NULL;
803809
gchar *remote_sessions_dir = NULL;
804810
gchar *xgreeters_dir = NULL;
805-
gchar *config_dir;
811+
gchar *config_dir, *config_d_dir = NULL;
806812
gchar *log_dir = NULL;
807813
gchar *run_dir = NULL;
808814
gchar *cache_dir = NULL;
809815
gchar *default_log_dir = g_strdup (LOG_DIR);
810816
gchar *default_run_dir = g_strdup (RUN_DIR);
811817
gchar *default_cache_dir = g_strdup (CACHE_DIR);
812818
gboolean show_version = FALSE;
819+
GList *link, *messages = NULL;
813820
GOptionEntry options[] =
814821
{
815822
{ "config", 'c', 0, G_OPTION_ARG_STRING, &config_path,
@@ -858,6 +865,8 @@ main (int argc, char **argv)
858865
#endif
859866
loop = g_main_loop_new (NULL, FALSE);
860867

868+
messages = g_list_append (messages, g_strdup_printf ("Starting Light Display Manager %s, UID=%i PID=%i", VERSION, getuid (), getpid ()));
869+
861870
g_signal_connect (process_get_current (), "got-signal", G_CALLBACK (signal_cb), NULL);
862871

863872
option_context = g_option_context_new (/* Arguments and description for --help test */
@@ -892,6 +901,7 @@ main (int argc, char **argv)
892901
else
893902
{
894903
config_dir = g_strdup (CONFIG_DIR);
904+
config_d_dir = g_build_filename (config_dir, "lightdm.conf.d", NULL);
895905
config_path = g_build_filename (config_dir, "lightdm.conf", NULL);
896906
}
897907
config_set_string (config_get_instance (), "LightDM", "config-directory", config_dir);
@@ -955,7 +965,8 @@ main (int argc, char **argv)
955965
default_cache_dir = g_build_filename (g_get_user_cache_dir (), "lightdm", "cache", NULL);
956966
}
957967

958-
/* Load config file */
968+
/* Load config file(s) */
969+
messages = g_list_append (messages, g_strdup_printf ("Loading configuration from %s", config_path));
959970
if (!config_load_from_file (config_get_instance (), config_path, &error))
960971
{
961972
gboolean is_empty;
@@ -970,6 +981,49 @@ main (int argc, char **argv)
970981
}
971982
}
972983
g_clear_error (&error);
984+
g_free (config_path);
985+
if (config_d_dir)
986+
{
987+
GDir *dir;
988+
GList *files, *link;
989+
GKeyFile *f;
990+
991+
/* Find configuration files */
992+
dir = g_dir_open (config_d_dir, 0, &error);
993+
if (error && !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
994+
g_printerr ("Failed to open configuration directory %s: %s\n", config_d_dir, error->message);
995+
g_clear_error (&error);
996+
if (dir)
997+
{
998+
const gchar *name;
999+
while ((name = g_dir_read_name (dir)))
1000+
files = g_list_append (files, g_strdup (name));
1001+
g_dir_close (dir);
1002+
}
1003+
1004+
/* Sort alphabetically and load onto existing configuration */
1005+
files = g_list_sort (files, compare_strings);
1006+
for (link = files; link; link = link->next)
1007+
{
1008+
gchar *filename = link->data;
1009+
gchar *path;
1010+
1011+
path = g_build_filename (config_d_dir, filename, NULL);
1012+
if (g_str_has_suffix (filename, ".conf"))
1013+
{
1014+
messages = g_list_append (messages, g_strdup_printf ("Loading configuration from %s", path));
1015+
config_load_from_file (config_get_instance (), path, &error);
1016+
if (error && !g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
1017+
g_printerr ("Failed to load configuration from %s: %s\n", filename, error->message);
1018+
g_clear_error (&error);
1019+
}
1020+
else
1021+
g_debug ("Ignoring configuration file %s, it does not have .conf suffix", path);
1022+
g_free (path);
1023+
}
1024+
g_list_free_full (files, g_free);
1025+
}
1026+
g_free (config_d_dir);
9731027

9741028
/* Set default values */
9751029
if (!config_has_key (config_get_instance (), "LightDM", "start-default-seat"))
@@ -1052,10 +1106,10 @@ main (int argc, char **argv)
10521106

10531107
log_init ();
10541108

1055-
g_debug ("Starting Light Display Manager %s, UID=%i PID=%i", VERSION, getuid (), getpid ());
1056-
1057-
g_debug ("Loaded configuration from %s", config_path);
1058-
g_free (config_path);
1109+
/* Show queued messages once logging is complete */
1110+
for (link = messages; link; link = link->next)
1111+
g_debug ("%s", link->data);
1112+
g_list_free_full (messages, g_free);
10591113

10601114
g_debug ("Using D-Bus name %s", LIGHTDM_BUS_NAME);
10611115
bus_id = g_bus_own_name (getuid () == 0 ? G_BUS_TYPE_SYSTEM : G_BUS_TYPE_SESSION,

tests/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ TESTS = \
66
test-greeter-not-installed \
77
test-greeter-xserver-crash \
88
test-no-config \
9+
test-additional-config \
910
test-headless \
1011
test-autologin \
1112
test-autologin-in-background \
@@ -236,6 +237,9 @@ EXTRA_DIST = \
236237
data/xgreeters/test-qt5-greeter.desktop \
237238
data/xsessions/alternative.desktop \
238239
data/xsessions/default.desktop \
240+
scripts/0-additional.conf \
241+
scripts/1-additional.conf \
242+
scripts/additional-config.conf \
239243
scripts/autologin.conf \
240244
scripts/autologin-guest.conf \
241245
scripts/autologin-guest-fail-setup-script.conf \

tests/scripts/0-additional.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[SeatDefaults]
2+
autologin-user=have-password1

tests/scripts/1-additional.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[SeatDefaults]
2+
autologin-user=have-password2

tests/scripts/additional-config.conf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# Check LightDM runs without a config.d configuration
3+
#
4+
5+
[test-runner-config]
6+
additional-config=0-additional.conf 1-additional.conf
7+
8+
#?RUNNER DAEMON-START
9+
10+
# X server starts
11+
#?XSERVER-0 START
12+
#?XSERVER-0 INDICATE-READY
13+
14+
# LightDM connects to X server
15+
#?XSERVER-0 ACCEPT-CONNECT
16+
17+
# Session starts
18+
#?SESSION-X-0 START USER=have-password2
19+
#?XSERVER-0 ACCEPT-CONNECT
20+
#?SESSION-X-0 CONNECT-XSERVER
21+
22+
# Cleanup
23+
#?*STOP-DAEMON
24+
#?SESSION-X-0 TERMINATE SIGNAL=15
25+
#?XSERVER-0 TERMINATE SIGNAL=15
26+
#?RUNNER DAEMON-EXIT STATUS=0

tests/src/libsystem.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <sys/stat.h>
66
#include <pwd.h>
77
#include <unistd.h>
8+
#include <dirent.h>
89
#include <grp.h>
910
#include <security/pam_appl.h>
1011
#include <fcntl.h>
@@ -357,6 +358,22 @@ __xstat64 (int version, const char *path, struct stat *buf)
357358
return ret;
358359
}
359360

361+
DIR *
362+
opendir (const char *name)
363+
{
364+
DIR *(*_opendir) (const char *name);
365+
gchar *new_path = NULL;
366+
DIR *result;
367+
368+
_opendir = (DIR *(*)(const char *name)) dlsym (RTLD_NEXT, "opendir");
369+
370+
new_path = redirect_path (name);
371+
result = _opendir (new_path);
372+
g_free (new_path);
373+
374+
return result;
375+
}
376+
360377
int
361378
mkdir (const char *pathname, mode_t mode)
362379
{

tests/src/test-runner.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,7 @@ main (int argc, char **argv)
16981698
{
16991699
GMainLoop *loop;
17001700
int i;
1701-
gchar *greeter = NULL, *script_name, *config_file, *path, *path1, *path2, *ld_preload, *ld_library_path, *home_dir;
1701+
gchar *greeter = NULL, *script_name, *config_file, *additional_config, *path, *path1, *path2, *ld_preload, *ld_library_path, *home_dir;
17021702
GString *passwd_data, *group_data;
17031703
GSource *status_source;
17041704
gchar cwd[1024];
@@ -1832,6 +1832,20 @@ main (int argc, char **argv)
18321832
if (system (g_strdup_printf ("cp %s %s/etc/lightdm/lightdm.conf", config_path, temp_dir)))
18331833
perror ("Failed to copy configuration");
18341834

1835+
additional_config = g_key_file_get_string (config, "test-runner-config", "additional-config", NULL);
1836+
if (additional_config)
1837+
{
1838+
gchar **files;
1839+
1840+
g_mkdir_with_parents (g_strdup_printf ("%s/etc/lightdm/lightdm.conf.d", temp_dir), 0755);
1841+
1842+
files = g_strsplit (additional_config, " ", -1);
1843+
for (i = 0; files[i]; i++)
1844+
if (system (g_strdup_printf ("cp scripts/%s %s/etc/lightdm/lightdm.conf.d", files[i], temp_dir)))
1845+
perror ("Failed to copy configuration");
1846+
g_strfreev (files);
1847+
}
1848+
18351849
/* Always copy the script */
18361850
if (system (g_strdup_printf ("cp %s %s/script", config_path, temp_dir)))
18371851
perror ("Failed to copy configuration");

tests/test-additional-config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
./src/dbus-env ./src/test-runner additional-config test-gobject-greeter

0 commit comments

Comments
 (0)