From 5b4b6b2aad548cdc27ba2aa7d87ff584ec7e97dd Mon Sep 17 00:00:00 2001 From: Michaël Lefèvre Date: Thu, 20 Mar 2014 21:27:40 +0100 Subject: fdo#56284 : soffice fails to start unless ~/.config exists and is writable Try to create $HOME/.config if not present. If present, check that it's a directory with RWX user permission Change-Id: Icef558b2185ad7a7b3518d097f7b62a0b3344083 Signed-off-by: Stephan Bergmann --- sal/osl/unx/security.c | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/sal/osl/unx/security.c b/sal/osl/unx/security.c index 2be082644507..3806a0f96b2d 100644 --- a/sal/osl/unx/security.c +++ b/sal/osl/unx/security.c @@ -395,6 +395,8 @@ static sal_Bool SAL_CALL osl_psz_getConfigDir(oslSecurity Security, sal_Char* ps if (pStr == NULL || strlen(pStr) == 0 || access(pStr, 0) != 0) { size_t n = 0; + sal_Bool dirOK = sal_True; + // a default equal to $HOME/.config should be used. if (!osl_psz_getHomeDir(Security, pszDirectory, nMax)) return sal_False; @@ -402,11 +404,37 @@ static sal_Bool SAL_CALL osl_psz_getConfigDir(oslSecurity Security, sal_Char* ps if (n + sizeof(DOT_CONFIG) < nMax) { strncpy(pszDirectory+n, DOT_CONFIG, sizeof(DOT_CONFIG)); - if (access(pszDirectory, 0) != 0) + + // try to create dir if not present + if (access(pszDirectory, F_OK) != 0 && mkdir(pszDirectory, S_IRWXU) != 0) + dirOK = sal_False; + else { - // resort to HOME - pszDirectory[n] = '\0'; + // check file type and permissions + struct stat st; + if (stat(pszDirectory, &st) != 0) + { + OSL_TRACE("Could not stat $HOME/.config"); + dirOK = sal_False; + } + else + { + if (!S_ISDIR(st.st_mode)) + { + OSL_TRACE("$HOME/.config is not a directory"); + dirOK = sal_False; + } + if (!(st.st_mode & S_IRUSR && st.st_mode & S_IWUSR && st.st_mode & S_IXUSR)) + { + OSL_TRACE("$HOME/.config has bad permissions"); + dirOK = sal_False; + } + } } + + // resort to HOME + if (dirOK == sal_False) + pszDirectory[n] = '\0'; } } else -- cgit v1.2.3