From 27072c0a42509709f440e0c1531e3d218a32efcd Mon Sep 17 00:00:00 2001 Message-Id: <27072c0a42509709f440e0c1531e3d218a32efcd.1351979134.git.matthew.monaco@0x01b.net> In-Reply-To: <0055b44cafe7d7bb6c5fb0d50d22fa4fc7978745.1351979134.git.matthew.monaco@0x01b.net> References: <0055b44cafe7d7bb6c5fb0d50d22fa4fc7978745.1351979134.git.matthew.monaco@0x01b.net> From: Matthew Monaco Date: Sat, 3 Nov 2012 14:35:19 -0600 Subject: [PATCH 3/4] cfg: replace default_excludes with configuration file --- data/accountsservice.conf | 4 ++++ src/config.c | 11 +++++++++++ src/daemon.c | 43 ++++++++++--------------------------------- src/util.h | 2 ++ 4 files changed, 27 insertions(+), 33 deletions(-) diff --git a/data/accountsservice.conf b/data/accountsservice.conf index ac7c06e..bd2bc47 100644 --- a/data/accountsservice.conf +++ b/data/accountsservice.conf @@ -1,3 +1,7 @@ # # Configuration for AccountsService # + +[UserList] + +Exclude = root daemon adm lp sync shutdown halt mail news uucp operator nobody nobody4 noaccess postgres pvm rpm nfsnobody pcap mysql ftp games man at diff --git a/src/config.c b/src/config.c index 08a6b0f..41d25a2 100644 --- a/src/config.c +++ b/src/config.c @@ -29,6 +29,7 @@ Config *cfg_init() b = g_key_file_load_from_file(f, PATH_CONFIG_FILE, G_KEY_FILE_NONE, NULL); if (b) { + g_key_file_set_list_separator(f, ' '); return (Config*) f; } else { g_key_file_free(f); @@ -42,5 +43,15 @@ void cfg_free(Config *cfg) g_key_file_free(f); } +gchar **cfg_get_excludes(Config *cfg) +{ + return g_key_file_get_string_list(cfg, "UserList", "Exclude", NULL, NULL); +} + +void cfg_free_excludes(Config *cfg, gchar **e) +{ + g_strfreev(e); +} + /* vim: set ts=8 sw=8 sts=8 et : */ diff --git a/src/daemon.c b/src/daemon.c index 4b32122..78d3db7 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -51,35 +51,6 @@ #define PATH_FALSE "/bin/false" #define PATH_GDM_CUSTOM "/etc/gdm/custom.conf" -static const char *default_excludes[] = { - "bin", - "root", - "daemon", - "adm", - "lp", - "sync", - "shutdown", - "halt", - "mail", - "news", - "uucp", - "operator", - "nobody", - "nobody4", - "noaccess", - "postgres", - "pvm", - "rpm", - "nfsnobody", - "pcap", - "mysql", - "ftp", - "games", - "man", - "at", - NULL -}; - enum { PROP_0, PROP_DAEMON_VERSION @@ -634,21 +605,27 @@ daemon_init (Daemon *daemon) gint i; GFile *file; GError *error; + gchar **excludes; Config *cfg; cfg = cfg_init(); daemon->priv = DAEMON_GET_PRIVATE (daemon); + excludes = cfg_get_excludes(cfg); daemon->priv->exclusions = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - for (i = 0; default_excludes[i] != NULL; i++) { - g_hash_table_insert (daemon->priv->exclusions, - g_strdup (default_excludes[i]), - GUINT_TO_POINTER (TRUE)); + if (excludes) { + for (i = 0; excludes[i] != NULL; i++) { + g_hash_table_insert (daemon->priv->exclusions, + g_strdup (excludes[i]), + GUINT_TO_POINTER (TRUE)); + } + + cfg_free_excludes(cfg, excludes); } daemon->priv->users = create_users_hash_table (); diff --git a/src/util.h b/src/util.h index ff88973..8d7ed7c 100644 --- a/src/util.h +++ b/src/util.h @@ -33,6 +33,8 @@ G_BEGIN_DECLS typedef GKeyFile Config; Config* cfg_init(void); void cfg_free(Config*); +gchar **cfg_get_excludes(Config*); +void cfg_free_excludes(Config*, gchar**); void sys_log (GDBusMethodInvocation *context, const gchar *format, -- 1.8.0