Kaydet (Commit) 88d46ba3 authored tarafından Takeshi Abe's avatar Takeshi Abe Kaydeden (comit) Caolán McNamara

tdf#119890 followup: Forbid HOME to be the default dir

... of user templates

This is kludgy yet better than making innocent users waiting for
the template dialog ~forever as pointed out in the comments in
<https://gerrit.libreoffice.org/#/c/67741/>.

Change-Id: I6dfdc0408effb06cc9175cd976ea6687e52a7136
Reviewed-on: https://gerrit.libreoffice.org/69883
Tested-by: Jenkins
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst bf9f0b29
...@@ -127,7 +127,7 @@ void Default::setPropertyValue(OUString const &, css::uno::Any const &) ...@@ -127,7 +127,7 @@ void Default::setPropertyValue(OUString const &, css::uno::Any const &)
static_cast< cppu::OWeakObject * >(this), -1); static_cast< cppu::OWeakObject * >(this), -1);
} }
OUString xdg_user_dir_lookup (const char *type) OUString xdg_user_dir_lookup (const char *type, bool bAllowHomeDir)
{ {
size_t nLenType = strlen(type); size_t nLenType = strlen(type);
char *config_home; char *config_home;
...@@ -218,16 +218,20 @@ OUString xdg_user_dir_lookup (const char *type) ...@@ -218,16 +218,20 @@ OUString xdg_user_dir_lookup (const char *type)
if (aUserDirBuf.getLength()>0 && !bError) if (aUserDirBuf.getLength()>0 && !bError)
{ {
aDocumentsDirURL = aUserDirBuf.makeStringAndClear(); aDocumentsDirURL = aUserDirBuf.makeStringAndClear();
osl::Directory aDocumentsDir( aDocumentsDirURL ); if ( bAllowHomeDir ||
if( osl::FileBase::E_None == aDocumentsDir.open() ) (aDocumentsDirURL != aHomeDirURL && aDocumentsDirURL != aHomeDirURL + "/") )
return aDocumentsDirURL; {
osl::Directory aDocumentsDir( aDocumentsDirURL );
if( osl::FileBase::E_None == aDocumentsDir.open() )
return aDocumentsDirURL;
}
} }
/* Use fallbacks historical compatibility if nothing else exists */ /* Use fallbacks historical compatibility if nothing else exists */
return aHomeDirURL + "/" + OUString::createFromAscii(type); return aHomeDirURL + "/" + OUString::createFromAscii(type);
} }
css::uno::Any xdgDirectoryIfExists(char const * type) { css::uno::Any xdgDirectoryIfExists(char const * type, bool bAllowHomeDir) {
auto url = xdg_user_dir_lookup(type); auto url = xdg_user_dir_lookup(type, bAllowHomeDir);
return css::uno::Any( return css::uno::Any(
osl::Directory(url).open() == osl::FileBase::E_None osl::Directory(url).open() == osl::FileBase::E_None
? css::beans::Optional<css::uno::Any>(true, css::uno::Any(url)) ? css::beans::Optional<css::uno::Any>(true, css::uno::Any(url))
...@@ -238,12 +242,13 @@ css::uno::Any Default::getPropertyValue(OUString const & PropertyName) ...@@ -238,12 +242,13 @@ css::uno::Any Default::getPropertyValue(OUString const & PropertyName)
{ {
if (PropertyName == "TemplatePathVariable") if (PropertyName == "TemplatePathVariable")
{ {
return xdgDirectoryIfExists("Templates"); // Never pick up the HOME directory as the default location of user's templates
return xdgDirectoryIfExists("Templates", false);
} }
if (PropertyName == "WorkPathVariable") if (PropertyName == "WorkPathVariable")
{ {
return xdgDirectoryIfExists("Documents"); return xdgDirectoryIfExists("Documents", true);
} }
if ( PropertyName == "EnableATToolSupport" || if ( PropertyName == "EnableATToolSupport" ||
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment