[telepathy-mission-control/master] Store the accounts cache in $XDG_CACHE_DIR by default

Simon McVittie simon.mcvittie at collabora.co.uk
Thu May 14 10:51:08 PDT 2009


Using /tmp renders MC unusable for more than one desktop user at a time,
and also makes desktop users vulnerable to an easy symlink attack.

For testing, MC_ACCOUNT_DIR in the environment takes precedence.

For embedded use, --with-accounts-cache-dir=/some/tmpfs can be used to
restore the old behaviour.
---
 configure.ac              |   10 ++++++++++
 src/mcd-account-manager.c |   21 ++++++++++++++++++++-
 test/twisted/Makefile.am  |    1 +
 3 files changed, 31 insertions(+), 1 deletions(-)

diff --git a/configure.ac b/configure.ac
index bb28e79..6a54a99 100644
--- a/configure.ac
+++ b/configure.ac
@@ -150,6 +150,16 @@ AC_SUBST(ACCOUNTS_DIR)
 AC_DEFINE_UNQUOTED(ACCOUNTS_DIR,"$ACCOUNTS_DIR", [Directory for storing accounts])
 
 
+AC_ARG_WITH(accounts_cache_dir, AS_HELP_STRING([--with-accounts-cache-dir=<path>],[Directory for account/connection mapping for crash recovery]))
+if test -z "$with_accounts_dir" ; then
+    ACCOUNTS_CACHE_DIR=""
+else
+    ACCOUNTS_CACHE_DIR=$with_accounts_dir
+fi
+AC_SUBST(ACCOUNTS_CACHE_DIR)
+AC_DEFINE_UNQUOTED(ACCOUNTS_CACHE_DIR,"$ACCOUNTS_CACHE_DIR", [Directory for account/connection mapping for crash recovery])
+
+
 AC_ARG_WITH(chandlers_dir, AS_HELP_STRING([--with-chandlers-dir=<path>],[Directory for channel handlers]))
 if test -z "$with_chandlers_dir" ; then
     CHANDLERS_DIR="telepathy/managers"
diff --git a/src/mcd-account-manager.c b/src/mcd-account-manager.c
index f52f435..e0e1993 100644
--- a/src/mcd-account-manager.c
+++ b/src/mcd-account-manager.c
@@ -968,6 +968,24 @@ mcd_account_manager_class_init (McdAccountManagerClass *klass)
                               G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
 }
 
+static const gchar *
+get_connections_cache_dir (void)
+{
+    const gchar *from_env = g_getenv ("MC_ACCOUNT_DIR");
+
+    if (from_env != NULL)
+    {
+        return from_env;
+    }
+
+    if ((ACCOUNTS_CACHE_DIR)[0] != '\0')
+    {
+        return ACCOUNTS_CACHE_DIR;
+    }
+
+    return g_get_user_cache_dir ();
+}
+
 static void
 mcd_account_manager_init (McdAccountManager *account_manager)
 {
@@ -984,7 +1002,8 @@ mcd_account_manager_init (McdAccountManager *account_manager)
 					    NULL, unref_account);
 
     priv->account_connections_file =
-        g_build_filename (g_get_tmp_dir (), ".mc_connections", NULL);
+        g_build_filename (get_connections_cache_dir (), ".mc_connections",
+                          NULL);
 
     priv->keyfile = g_key_file_new ();
     conf_filename = get_account_conf_filename ();
diff --git a/test/twisted/Makefile.am b/test/twisted/Makefile.am
index 23b40f0..c99d2fe 100644
--- a/test/twisted/Makefile.am
+++ b/test/twisted/Makefile.am
@@ -51,6 +51,7 @@ BASIC_TESTS_ENVIRONMENT = \
 	MC_ACCOUNT_DIR=@abs_top_builddir@/test/twisted/accounts \
 	XDG_DATA_HOME=@abs_top_builddir@/test/twisted \
 	XDG_DATA_DIRS=@abs_top_srcdir@/test/twisted \
+	XDG_CACHE_DIR=@abs_top_builddir@/test/twisted \
 	MC_CLIENTS_DIR=@abs_top_builddir@/test/twisted/telepathy/clients \
 	MC_MANAGER_DIR=@abs_top_builddir@/test/twisted/telepathy/managers \
 	G_DEBUG=fatal_criticals
-- 
1.5.6.5




More information about the telepathy-commits mailing list