diff options
author | Michaël Lefèvre <lefevre00@yahoo.fr> | 2014-03-20 21:27:40 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2014-03-24 10:41:38 +0100 |
commit | 5b4b6b2aad548cdc27ba2aa7d87ff584ec7e97dd (patch) | |
tree | 1d31dc1293e6bef571a8035ff2f2e0be41accced /sal | |
parent | 0a841226089679d2fed752607ce157ad0f5af330 (diff) |
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 <sbergman@redhat.com>
Diffstat (limited to 'sal')
-rw-r--r-- | sal/osl/unx/security.c | 34 |
1 files 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 |