Hi,
Here is a my first attempt at a patch, fixing Bug 43895 (Never let users
save in /tmp by default).
I was debating adding a warning for anyone saving to /tmp, however I
doubt anyone would do this accidentally except in the case of
downloading through firefox, which is now fixed. (Incidentally Chromium
and Rekonq don't seem to allow direct opening of files -- they force the
user to save the file first -- so this fix is pretty much firefox specific).
(Contributed under the LGPLv3+ / MPL.)
Regards,
Andrzej Hunt
diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx
index 3bf4fb5..00d53be 100644
--- a/sfx2/source/dialog/filedlghelper.cxx
+++ b/sfx2/source/dialog/filedlghelper.cxx
@@ -26,6 +26,7 @@
*
************************************************************************/
+#include <sys/stat.h>
#include <sfx2/filedlghelper.hxx>
#include <sal/types.h>
#include <com/sun/star/lang/XInitialization.hpp>
@@ -1635,6 +1636,21 @@ void FileDialogHelper_Impl::getRealFilter( String& _rFilter ) const
}
}
+void FileDialogHelper_Impl::verifyPath()
+{
+ struct stat aFileStat;
+ const char* pFullPath = OUStringToOString( ( maPath.copy(7) + maFileName ),
+ osl_getThreadTextEncoding() ).getStr();
+ stat( pFullPath, &aFileStat );
+ // Check that the file has read only permission and is in /tmp -- this is
+ // the case if we have opened the file from the web with firefox only.
+ if ( maPath.compareTo("file:///tmp",11) == 0 &&
+ ( aFileStat.st_mode & (S_IRWXO + S_IRWXG + S_IRWXU) ) == S_IRUSR ) {
+ maPath = SvtPathOptions().GetWorkPath();
+ mxFileDlg->setDisplayDirectory( maPath );
+ }
+}
+
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::displayFolder( const ::rtl::OUString& _rPath )
{
@@ -1648,6 +1664,7 @@ void FileDialogHelper_Impl::displayFolder( const ::rtl::OUString& _rPath )
try
{
mxFileDlg->setDisplayDirectory( maPath );
+ verifyPath();
}
catch( const IllegalArgumentException& )
{
@@ -1665,6 +1682,7 @@ void FileDialogHelper_Impl::setFileName( const ::rtl::OUString& _rFile )
try
{
mxFileDlg->setDefaultName( maFileName );
+ verifyPath();
}
catch( const IllegalArgumentException& )
{
diff --git a/sfx2/source/dialog/filedlgimpl.hxx b/sfx2/source/dialog/filedlgimpl.hxx
index 4f4e86d..149ac66 100644
--- a/sfx2/source/dialog/filedlgimpl.hxx
+++ b/sfx2/source/dialog/filedlgimpl.hxx
@@ -151,6 +151,8 @@ namespace sfx2
void SaveLastUsedFilter( void );
void implInitializeFileName( );
+
+ void verifyPath( );
void implGetAndCacheFiles( const ::com::sun::star::uno::Reference<
XInterface >& xPicker ,
std::vector<rtl::OUString>&
rpURLList,
Context
- [PATCH] Fix for Bug 43895: Never let users save in /tmp by default · Andrzej J. R. Hunt
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.