summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens-Heiner Rechtien <hr@openoffice.org>2009-01-06 16:18:24 +0000
committerJens-Heiner Rechtien <hr@openoffice.org>2009-01-06 16:18:24 +0000
commit56bfd8ec819cc24bcc7c142906609656aa5178a0 (patch)
tree393ebe34a8207dc91ab8737b57d3fae9deada260
parent4e1fd2fa161708049f1c3b6039659d0bf4f4539e (diff)
CWS-TOOLING: integrate CWS mav43
2008-12-17 14:42:56 +0100 tbo r265602 : #i97269# changed hid.lst and etab.win 2008-12-15 15:36:04 +0100 mav r265508 : #i95809# remove the stream as well 2008-12-12 13:20:09 +0100 mav r265411 : #i95809# small fixes 2008-12-12 13:12:07 +0100 mav r265410 : #i95809# fix streams handling 2008-12-12 10:45:29 +0100 mav r265397 : #i95809# close the stream if there is no storage 2008-12-12 10:24:38 +0100 mav r265396 : #i95809# close the stream if there is no temporary file 2008-12-12 00:56:13 +0100 mav r265383 : #i95809# adopt for linux 2008-12-12 00:51:25 +0100 mav r265382 : #i95809# adopt for linux 2008-12-12 00:38:31 +0100 mav r265381 : #i95809# check timestamp only if fs locking not active 2008-12-12 00:35:32 +0100 mav r265380 : #i95809# small fixes 2008-12-12 00:29:33 +0100 mav r265379 : #i95809# small fixes 2008-12-11 22:30:15 +0100 mav r265374 : #i97092# allow to use default master password 2008-12-11 22:20:56 +0100 mav r265372 : #i95809# avoid storage closing 2008-12-11 21:11:37 +0100 mav r265368 : #i97092# do not publish for now 2008-12-11 21:08:22 +0100 mav r265366 : #i95809# fix typo 2008-12-11 21:06:49 +0100 mav r265364 : #i95809# small fixes 2008-12-11 21:05:13 +0100 mav r265363 : #i95809# small fixes 2008-12-11 20:40:05 +0100 mav r265360 : #i95809# show warning if the document was touched 2008-12-11 20:39:44 +0100 mav r265359 : #i95809# show warning if the document was touched 2008-12-11 19:54:45 +0100 mav r265355 : #i95809# small fixes 2008-12-11 19:42:52 +0100 mav r265353 : #i95809# small fixes 2008-12-11 19:30:30 +0100 mav r265351 : #i95809# small fixes 2008-12-11 19:16:40 +0100 mav r265349 : #i95809# small fixes 2008-12-11 19:05:56 +0100 mav r265348 : #i95809# small fixes 2008-12-11 18:26:03 +0100 mav r265346 : #i95809# ignore the exception 2008-12-11 18:19:28 +0100 mav r265345 : #i95809# pure imput stream in case of local file URL means opening of document readonly 2008-12-11 17:41:56 +0100 mav r265341 : #i95809# unfortunately SfxMedium can not take the decision 2008-12-11 17:37:07 +0100 mav r265340 : #i95809# fix typo 2008-12-11 17:33:47 +0100 mav r265339 : #i95809# pure imput stream in case of local file URL means opening of document readonly 2008-12-11 16:12:26 +0100 mav r265330 : #i95809# let dialogs look better 2008-12-11 15:50:43 +0100 mav r265322 : #i97092# allow to use default master password 2008-12-11 13:35:39 +0100 mav r265295 : #i97092# allow to use default master password 2008-12-11 13:04:28 +0100 mav r265290 : #i97092# allow to use default master password 2008-12-11 12:34:52 +0100 mav r265284 : #i97092# allow to use default master password 2008-12-11 11:21:33 +0100 mav r265267 : #i95809# adopt for linux 2008-12-11 10:25:22 +0100 mav r265255 : #i97092# allow to use default master password 2008-12-11 10:24:35 +0100 mav r265254 : #i97092# allow to use default master password 2008-12-10 17:02:32 +0100 pb r265207 : fix: #i97092# more info text 2008-12-10 16:40:53 +0100 mav r265205 : #i95809# integrate new file locking UI in sfx workflow 2008-12-10 16:38:55 +0100 mav r265204 : #i95809# allow to ignore own lock on saving 2008-12-10 14:52:12 +0100 pb r265192 : fix: #i97092# new master password behavior 2008-12-10 14:51:22 +0100 pb r265191 : fix: #i97092# new master password bahavior 2008-12-10 14:49:46 +0100 pb r265189 : fix: #i97092# new master password bahavior 2008-12-10 10:55:19 +0100 mav r265155 : #i95809# allow to ignore own lock on saving 2008-12-09 17:47:51 +0100 mav r265124 : #i95809# allow to ignore own lock on saving 2008-12-07 11:24:57 +0100 mav r264949 : #i95809# let the request be derived from IOException 2008-12-05 18:31:35 +0100 mav r264915 : #i95809# use the locking related dialogs from InteractionHandler 2008-12-04 18:33:36 +0100 mav r264867 : #i95809# the requests for the new locking UI 2008-12-04 10:26:52 +0100 pb r264822 : fix: #i95809# new message boxes for locking 2008-12-04 10:23:51 +0100 pb r264821 : fix: #i95809# STR_OPENLOCKED_UNKNOWNUSER replaced by STR_UNKNOWNUSER 2008-12-04 10:18:23 +0100 pb r264820 : fix: #i95809# new message boxes for locking 2008-12-04 10:15:56 +0100 pb r264819 : fix: #i95809# new message boxes for locking 2008-12-03 16:06:46 +0100 mav r264796 : #i95809# system file locking support 2008-12-02 16:19:30 +0100 mav r264717 : #i95809# system file locking support 2008-12-02 16:07:10 +0100 mav r264716 : #i95809# system file locking support 2008-12-02 15:58:53 +0100 mav r264714 : #i95809# change the name 2008-12-02 15:58:06 +0100 mav r264713 : #i95809# do not allow to change ReadOnly flag in TypeDetection 2008-12-02 15:56:00 +0100 mav r264712 : #i95809# system file locking support 2008-12-02 15:43:20 +0100 mav r264708 : #i95809# change the name 2008-12-02 15:38:08 +0100 mav r264706 : #i95809# an options to control system file locking usage
-rw-r--r--comphelper/inc/comphelper/mediadescriptor.hxx44
-rw-r--r--comphelper/source/misc/mediadescriptor.cxx35
-rw-r--r--svtools/inc/svtools/documentlockfile.hxx1
-rw-r--r--svtools/source/inc/passwordcontainer.hxx12
-rw-r--r--svtools/source/misc/documentlockfile.cxx27
-rw-r--r--svtools/source/passwordcontainer/passwordcontainer.cxx184
6 files changed, 247 insertions, 56 deletions
diff --git a/comphelper/inc/comphelper/mediadescriptor.hxx b/comphelper/inc/comphelper/mediadescriptor.hxx
index f1a05de9de5a..5cd36d2e687b 100644
--- a/comphelper/inc/comphelper/mediadescriptor.hxx
+++ b/comphelper/inc/comphelper/mediadescriptor.hxx
@@ -151,16 +151,31 @@ class COMPHELPER_DLLPUBLIC MediaDescriptor : public SequenceAsHashMap
A might existing InteractionHandler will be used automaticly,
to solve problems!
- @param bLockFile
- specifies whether the file should be locked
+ In case of local file the system file locking is used.
@return TRUE, if the stream was already part of the descriptor or could
be created as new item. FALSE otherwhise.
*/
- // HACK: IT SHOULD BE ONLY ONE METHOD, THE TEMPORARY SOLUTION ALLOWS TO AVOID INCOMPATIBLE BUILD
- sal_Bool addInputStream_Impl( sal_Bool bLockFile );
sal_Bool addInputStream();
- sal_Bool addInputStreamNoLock();
+
+ //---------------------------------------
+ /** @short it checks if the descriptor already has a valid
+ InputStream item and creates a new one, if not.
+
+ @descr This method uses the current items of this MediaDescriptor,
+ to open the stream (as e.g. URL, ReadOnly, PostData etcpp.).
+ It creates a seekable stream and put it into the descriptor.
+
+ A might existing InteractionHandler will be used automaticly,
+ to solve problems!
+
+ In case of local file the system file locking is used based on
+ configuration settings.
+
+ @return TRUE, if the stream was already part of the descriptor or could
+ be created as new item. FALSE otherwhise.
+ */
+ sal_Bool addInputStreamOwnLock();
//---------------------------------------
/** @short it checks if the descriptor describes a readonly stream.
@@ -248,6 +263,25 @@ class COMPHELPER_DLLPUBLIC MediaDescriptor : public SequenceAsHashMap
the "normalized" URL (e.g. without jumpmark)
*/
COMPHELPER_DLLPRIVATE ::rtl::OUString impl_normalizeURL(const ::rtl::OUString& sURL);
+
+ //---------------------------------------
+ /** @short it checks if the descriptor already has a valid
+ InputStream item and creates a new one, if not.
+
+ @descr This method uses the current items of this MediaDescriptor,
+ to open the stream (as e.g. URL, ReadOnly, PostData etcpp.).
+ It creates a seekable stream and put it into the descriptor.
+
+ A might existing InteractionHandler will be used automaticly,
+ to solve problems!
+
+ @param bLockFile
+ specifies whether the file should be locked
+
+ @return TRUE, if the stream was already part of the descriptor or could
+ be created as new item. FALSE otherwhise.
+ */
+ COMPHELPER_DLLPRIVATE sal_Bool impl_addInputStream( sal_Bool bLockFile );
};
} // namespace comphelper
diff --git a/comphelper/source/misc/mediadescriptor.cxx b/comphelper/source/misc/mediadescriptor.cxx
index fe2a5a3801fe..da0dd71a5520 100644
--- a/comphelper/source/misc/mediadescriptor.cxx
+++ b/comphelper/source/misc/mediadescriptor.cxx
@@ -86,11 +86,14 @@
#include <com/sun/star/uri/XUriReference.hpp>
#endif
#include <com/sun/star/ucb/PostCommandArgument2.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
+
#include <ucbhelper/interceptedinteraction.hxx>
#include <ucbhelper/content.hxx>
#include <ucbhelper/commandenvironment.hxx>
#include <ucbhelper/activedatasink.hxx>
#include <comphelper/processfactory.hxx>
+#include <comphelper/configurationhelper.hxx>
#if OSL_DEBUG_LEVEL>0
#ifndef _RTL_USTRBUF_HXX_
@@ -501,15 +504,39 @@ sal_Bool MediaDescriptor::isStreamReadOnly() const
-----------------------------------------------*/
sal_Bool MediaDescriptor::addInputStream()
{
- return addInputStream_Impl( sal_True );
+ return impl_addInputStream( sal_True );
}
-sal_Bool MediaDescriptor::addInputStreamNoLock()
+/*-----------------------------------------------*/
+sal_Bool MediaDescriptor::addInputStreamOwnLock()
{
- return addInputStream_Impl( sal_False );
+ // Own lock file implementation
+
+ sal_Bool bUseLock = sal_True; // the system file locking is used per default
+ try
+ {
+
+ css::uno::Reference< css::uno::XInterface > xCommonConfig = ::comphelper::ConfigurationHelper::openConfig(
+ ::comphelper::getProcessServiceFactory(),
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common" ) ),
+ ::comphelper::ConfigurationHelper::E_STANDARD );
+ if ( !xCommonConfig.is() )
+ throw css::uno::RuntimeException();
+
+ ::comphelper::ConfigurationHelper::readRelativeKey(
+ xCommonConfig,
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Misc/" ) ),
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseDocumentSystemFileLocking" ) ) ) >>= bUseLock;
+ }
+ catch( const css::uno::Exception& )
+ {
+ }
+
+ return impl_addInputStream( bUseLock );
}
-sal_Bool MediaDescriptor::addInputStream_Impl( sal_Bool bLockFile )
+/*-----------------------------------------------*/
+sal_Bool MediaDescriptor::impl_addInputStream( sal_Bool bLockFile )
{
// check for an already existing stream item first
const_iterator pIt = find(MediaDescriptor::PROP_INPUTSTREAM());
diff --git a/svtools/inc/svtools/documentlockfile.hxx b/svtools/inc/svtools/documentlockfile.hxx
index 5fdda51acb5b..73e64f4f04a5 100644
--- a/svtools/inc/svtools/documentlockfile.hxx
+++ b/svtools/inc/svtools/documentlockfile.hxx
@@ -79,6 +79,7 @@ public:
sal_Bool CreateOwnLockFile();
::com::sun::star::uno::Sequence< ::rtl::OUString > GetLockData();
::com::sun::star::uno::Sequence< ::rtl::OUString > GenerateOwnEntry();
+ sal_Bool OverwriteOwnLockFile();
void RemoveFile();
// the methods allow to control whether UI interaction regarding the locked document file is allowed
diff --git a/svtools/source/inc/passwordcontainer.hxx b/svtools/source/inc/passwordcontainer.hxx
index 85b960a546b9..a6edea49f699 100644
--- a/svtools/source/inc/passwordcontainer.hxx
+++ b/svtools/source/inc/passwordcontainer.hxx
@@ -39,7 +39,7 @@
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <com/sun/star/lang/XEventListener.hpp>
#include <com/sun/star/lang/XComponent.hpp>
-#include <com/sun/star/task/XMasterPasswordHandling.hpp>
+#include <com/sun/star/task/XMasterPasswordHandling2.hpp>
#include <cppuhelper/implbase4.hxx>
#include <cppuhelper/typeprovider.hxx>
#include <cppuhelper/queryinterface.hxx>
@@ -225,7 +225,7 @@ public:
void clear();
sal_Bool getEncodedMP( ::rtl::OUString& aResult );
- void setEncodedMP( const ::rtl::OUString& aResult );
+ void setEncodedMP( const ::rtl::OUString& aResult, sal_Bool bAcceptEnmpty = sal_False );
void setUseStorage( sal_Bool bUse );
sal_Bool useStorage();
@@ -243,7 +243,7 @@ enum PasswordState {
class PasswordContainer : public ::cppu::WeakImplHelper4<
::com::sun::star::task::XPasswordContainer,
- ::com::sun::star::task::XMasterPasswordHandling,
+ ::com::sun::star::task::XMasterPasswordHandling2,
::com::sun::star::lang::XServiceInfo,
::com::sun::star::lang::XEventListener >
{
@@ -270,6 +270,8 @@ private:
const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler )
throw(::com::sun::star::uno::RuntimeException);
+ ::rtl::OUString GetDefaultMasterPassword();
+
::rtl::OUString RequestPasswordFromUser(
::com::sun::star::task::PasswordRequestMode aRMode,
const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& xHandler );
@@ -363,6 +365,10 @@ public:
virtual ::sal_Bool SAL_CALL allowPersistentStoring( ::sal_Bool bAllow ) throw (::com::sun::star::uno::RuntimeException);
virtual ::sal_Bool SAL_CALL isPersistentStoringAllowed( ) throw (::com::sun::star::uno::RuntimeException);
+ // XMasterPasswordHandling2
+ virtual ::sal_Bool SAL_CALL useDefaultMasterPassword( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& xHandler ) throw (::com::sun::star::uno::RuntimeException);
+ virtual ::sal_Bool SAL_CALL isDefaultMasterPasswordUsed( ) throw (::com::sun::star::uno::RuntimeException);
+
void Notify();
};
diff --git a/svtools/source/misc/documentlockfile.cxx b/svtools/source/misc/documentlockfile.cxx
index 24fe3349278f..c8904ef010a4 100644
--- a/svtools/source/misc/documentlockfile.cxx
+++ b/svtools/source/misc/documentlockfile.cxx
@@ -315,6 +315,33 @@ uno::Reference< io::XInputStream > DocumentLockFile::OpenStream()
}
// ----------------------------------------------------------------------
+sal_Bool DocumentLockFile::OverwriteOwnLockFile()
+{
+ // allows to overwrite the lock file with the current data
+ try
+ {
+ uno::Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv;
+ ::ucbhelper::Content aTargetContent( m_aURL, xEnv );
+
+ uno::Sequence< ::rtl::OUString > aNewEntry = GenerateOwnEntry();
+
+ uno::Reference< io::XStream > xStream = aTargetContent.openWriteableStreamNoLock();
+ uno::Reference< io::XOutputStream > xOutput = xStream->getOutputStream();
+ uno::Reference< io::XTruncate > xTruncate( xOutput, uno::UNO_QUERY_THROW );
+
+ xTruncate->truncate();
+ WriteEntryToStream( aNewEntry, xOutput );
+ xOutput->closeOutput();
+ }
+ catch( ucb::NameClashException& )
+ {
+ return sal_False;
+ }
+
+ return sal_True;
+}
+
+// ----------------------------------------------------------------------
void DocumentLockFile::RemoveFile()
{
// TODO/LATER: the removing is not atomar, is it possible in general to make it atomar?
diff --git a/svtools/source/passwordcontainer/passwordcontainer.cxx b/svtools/source/passwordcontainer/passwordcontainer.cxx
index 4683ea7041f8..9855e7e3c487 100644
--- a/svtools/source/passwordcontainer/passwordcontainer.cxx
+++ b/svtools/source/passwordcontainer/passwordcontainer.cxx
@@ -342,7 +342,7 @@ sal_Bool StorageItem::getEncodedMP( ::rtl::OUString& aResult )
//-------------------------------------------------------------------------
-void StorageItem::setEncodedMP( const ::rtl::OUString& aEncoded )
+void StorageItem::setEncodedMP( const ::rtl::OUString& aEncoded, sal_Bool bAcceptEmpty )
{
Sequence< ::rtl::OUString > sendNames(2);
Sequence< uno::Any > sendVals(2);
@@ -350,7 +350,7 @@ void StorageItem::setEncodedMP( const ::rtl::OUString& aEncoded )
sendNames[0] = ::rtl::OUString::createFromAscii( "HasMaster" );
sendNames[1] = ::rtl::OUString::createFromAscii( "Master" );
- sal_Bool bHasMaster = ( aEncoded.getLength() > 0 );
+ sal_Bool bHasMaster = ( aEncoded.getLength() > 0 || bAcceptEmpty );
sendVals[0] <<= bHasMaster;
sendVals[1] <<= aEncoded;
@@ -858,6 +858,16 @@ UrlRecord SAL_CALL PasswordContainer::findForName( const ::rtl::OUString& aURL,
}
//-------------------------------------------------------------------------
+::rtl::OUString PasswordContainer::GetDefaultMasterPassword()
+{
+ ::rtl::OUString aResult;
+ for ( sal_Int32 nInd = 0; nInd < RTL_DIGEST_LENGTH_MD5; nInd++ )
+ aResult += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "aa" ) );
+
+ return aResult;
+}
+
+//-------------------------------------------------------------------------
::rtl::OUString PasswordContainer::RequestPasswordFromUser( PasswordRequestMode aRMode, const uno::Reference< task::XInteractionHandler >& xHandler )
{
// empty string means that the call was cancelled or just failed
@@ -898,38 +908,47 @@ UrlRecord SAL_CALL PasswordContainer::findForName( const ::rtl::OUString& aURL,
if( !m_aMasterPasswd.getLength() && aHandler.is() )
{
::rtl::OUString aEncodedMP;
- sal_Bool bAskAgain;
+ sal_Bool bAskAgain = sal_False;
+ sal_Bool bDefaultPassword = sal_False;
if( !m_pStorageFile->getEncodedMP( aEncodedMP ) )
aRMode = PasswordRequestMode_PASSWORD_CREATE;
+ else if ( !aEncodedMP.getLength() )
+ {
+ m_aMasterPasswd = GetDefaultMasterPassword();
+ bDefaultPassword = sal_True;
+ }
- do {
- bAskAgain = sal_False;
-
- ::rtl::OUString aPass = RequestPasswordFromUser( aRMode, aHandler );
- if ( aPass.getLength() )
- {
- if( aRMode == PasswordRequestMode_PASSWORD_CREATE )
- {
- m_aMasterPasswd = aPass;
- vector< ::rtl::OUString > aMaster( 1, m_aMasterPasswd );
+ if ( !bDefaultPassword )
+ {
+ do {
+ bAskAgain = sal_False;
- m_pStorageFile->setEncodedMP( EncodePasswords( aMaster, m_aMasterPasswd ) );
- }
- else
+ ::rtl::OUString aPass = RequestPasswordFromUser( aRMode, aHandler );
+ if ( aPass.getLength() )
{
- vector< ::rtl::OUString > aRM( DecodePasswords( aEncodedMP, aPass ) );
- if( !aRM.size() || !aPass.equals( aRM[0] ) )
+ if( aRMode == PasswordRequestMode_PASSWORD_CREATE )
{
- bAskAgain = sal_True;
- aRMode = PasswordRequestMode_PASSWORD_REENTER;
+ m_aMasterPasswd = aPass;
+ vector< ::rtl::OUString > aMaster( 1, m_aMasterPasswd );
+
+ m_pStorageFile->setEncodedMP( EncodePasswords( aMaster, m_aMasterPasswd ) );
}
else
- m_aMasterPasswd = aPass;
+ {
+ vector< ::rtl::OUString > aRM( DecodePasswords( aEncodedMP, aPass ) );
+ if( !aRM.size() || !aPass.equals( aRM[0] ) )
+ {
+ bAskAgain = sal_True;
+ aRMode = PasswordRequestMode_PASSWORD_REENTER;
+ }
+ else
+ m_aMasterPasswd = aPass;
+ }
}
- }
- } while( bAskAgain );
+ } while( bAskAgain );
+ }
}
if ( !m_aMasterPasswd.getLength() )
@@ -1110,33 +1129,42 @@ sal_Bool SAL_CALL PasswordContainer::authorizateWithMasterPassword( const uno::R
// the method should fail if there is no master password
if( m_pStorageFile && m_pStorageFile->useStorage() && m_pStorageFile->getEncodedMP( aEncodedMP ) )
{
- if ( !xTmpHandler.is() )
+ if ( !aEncodedMP.getLength() )
{
- uno::Reference< lang::XMultiServiceFactory > xFactory( mComponent, uno::UNO_QUERY_THROW );
- xTmpHandler.set( xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.task.InteractionHandler" ) ) ), uno::UNO_QUERY_THROW );
- }
-
- if ( m_aMasterPasswd.getLength() )
- {
- // there is a password, it should be just rechecked
- PasswordRequestMode aRMode = PasswordRequestMode_PASSWORD_ENTER;
- ::rtl::OUString aPass;
-
- do {
- aPass = RequestPasswordFromUser( aRMode, xTmpHandler );
- bResult = ( aPass.getLength() && aPass.equals( m_aMasterPasswd ) );
- aRMode = PasswordRequestMode_PASSWORD_REENTER; // further questions with error notification
- } while( !bResult && aPass.getLength() );
+ // this is a default master password
+ // no UI is necessary
+ bResult = sal_True;
}
else
{
- try
+ if ( !xTmpHandler.is() )
+ {
+ uno::Reference< lang::XMultiServiceFactory > xFactory( mComponent, uno::UNO_QUERY_THROW );
+ xTmpHandler.set( xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.task.InteractionHandler" ) ) ), uno::UNO_QUERY_THROW );
+ }
+
+ if ( m_aMasterPasswd.getLength() )
+ {
+ // there is a password, it should be just rechecked
+ PasswordRequestMode aRMode = PasswordRequestMode_PASSWORD_ENTER;
+ ::rtl::OUString aPass;
+
+ do {
+ aPass = RequestPasswordFromUser( aRMode, xTmpHandler );
+ bResult = ( aPass.getLength() && aPass.equals( m_aMasterPasswd ) );
+ aRMode = PasswordRequestMode_PASSWORD_REENTER; // further questions with error notification
+ } while( !bResult && aPass.getLength() );
+ }
+ else
{
- // ask for the password, if user provide no correct password an exception will be thrown
- bResult = ( GetMasterPassword( xTmpHandler ).getLength() > 0 );
+ try
+ {
+ // ask for the password, if user provide no correct password an exception will be thrown
+ bResult = ( GetMasterPassword( xTmpHandler ).getLength() > 0 );
+ }
+ catch( uno::Exception& )
+ {}
}
- catch( uno::Exception& )
- {}
}
}
@@ -1260,6 +1288,74 @@ void SAL_CALL PasswordContainer::removeMasterPassword()
}
//-------------------------------------------------------------------------
+::sal_Bool SAL_CALL PasswordContainer::useDefaultMasterPassword( const uno::Reference< task::XInteractionHandler >& xHandler )
+ throw ( uno::RuntimeException )
+{
+ sal_Bool bResult = sal_False;
+ uno::Reference< task::XInteractionHandler > xTmpHandler = xHandler;
+ ::osl::MutexGuard aGuard( mMutex );
+
+ if ( m_pStorageFile && m_pStorageFile->useStorage() )
+ {
+ if ( !xTmpHandler.is() )
+ {
+ uno::Reference< lang::XMultiServiceFactory > xFactory( mComponent, uno::UNO_QUERY_THROW );
+ xTmpHandler.set( xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.task.InteractionHandler" ) ) ), uno::UNO_QUERY_THROW );
+ }
+
+ sal_Bool bCanChangePassword = sal_True;
+ // if there is already a stored nondefault master password it should be entered by the user before the change happen
+ ::rtl::OUString aEncodedMP;
+ if( m_pStorageFile->getEncodedMP( aEncodedMP ) && aEncodedMP.getLength() )
+ bCanChangePassword = authorizateWithMasterPassword( xTmpHandler );
+
+ if ( bCanChangePassword )
+ {
+ // generate the default password
+ ::rtl::OUString aPass = GetDefaultMasterPassword();
+ if ( aPass.getLength() )
+ {
+ // get all the persistent entries if it is possible
+ Sequence< UrlRecord > aPersistent = getAllPersistent( uno::Reference< task::XInteractionHandler >() );
+
+ // remove the master password and the entries persistence
+ removeMasterPassword();
+
+ // store the empty string to flag the default master password
+ m_aMasterPasswd = aPass;
+ m_pStorageFile->setEncodedMP( ::rtl::OUString(), sal_True );
+
+ // store all the entries with the new password
+ for ( int nURLInd = 0; nURLInd < aPersistent.getLength(); nURLInd++ )
+ for ( int nNameInd = 0; nNameInd< aPersistent[nURLInd].UserList.getLength(); nNameInd++ )
+ addPersistent( aPersistent[nURLInd].Url,
+ aPersistent[nURLInd].UserList[nNameInd].UserName,
+ aPersistent[nURLInd].UserList[nNameInd].Passwords,
+ uno::Reference< task::XInteractionHandler >() );
+
+ bResult = sal_True;
+ }
+ }
+ }
+
+ return bResult;
+
+}
+
+//-------------------------------------------------------------------------
+::sal_Bool SAL_CALL PasswordContainer::isDefaultMasterPasswordUsed()
+ throw ( uno::RuntimeException )
+{
+ ::osl::MutexGuard aGuard( mMutex );
+
+ if ( !m_pStorageFile )
+ throw uno::RuntimeException();
+
+ ::rtl::OUString aEncodedMP;
+ return ( m_pStorageFile->useStorage() && m_pStorageFile->getEncodedMP( aEncodedMP ) && !aEncodedMP.getLength() );
+}
+
+//-------------------------------------------------------------------------
void PasswordContainer::Notify()
{