diff options
author | Oliver-Rainer Wittmann <orw@apache.org> | 2012-06-26 13:48:58 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-05-02 12:09:33 +0100 |
commit | cdfad2dbbf180d3c556964c7aa8e0bb3b299d5e3 (patch) | |
tree | 8252bde9d7999015245ed0e64c533e72c0b211d7 /sfx2 | |
parent | 4314e6548356a5d2f1dc45e2aa501e37bd5a794e (diff) |
Resolves: #i119366# ensure password can be removed via "Save As..."
Found by: DonJaime <donjaime at freenet dot de>
Patch by: zhengfan <zheng.easyfan at gmail dot com>
Review by: Oliver <orw at apache dot org>
(cherry picked from commit 9957730bb807c6d81f243e14a19cbb6a91035194)
Conflicts:
sfx2/source/doc/sfxbasemodel.cxx
Change-Id: I93bfdd7f32671171f1b219f9fd2dbeac30a92254
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/doc/objstor.cxx | 3 | ||||
-rw-r--r-- | sfx2/source/doc/sfxbasemodel.cxx | 72 |
2 files changed, 45 insertions, 30 deletions
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index b92a10a048df..c57c79a45549 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -2749,6 +2749,9 @@ sal_Bool SfxObjectShell::PreDoSaveAs_Impl // in "SaveAs" title and password will be cleared ( maybe the new itemset contains new values, otherwise they will be empty ) pMergedParams->ClearItem( SID_ENCRYPTIONDATA ); pMergedParams->ClearItem( SID_PASSWORD ); + // #i119366# - As the SID_ENCRYPTIONDATA and SID_PASSWORD are using for setting password together, we need to clear them both. + // Also, ( maybe the new itemset contains new values, otherwise they will be empty ) + pMergedParams->ClearItem( SID_ENCRYPTIONDATA ); pMergedParams->ClearItem( SID_DOCINFO_TITLE ); pMergedParams->ClearItem( SID_INPUTSTREAM ); diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx index 90fe7e53fdbe..d5d5814d8fa9 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -2950,45 +2950,57 @@ void SfxBaseModel::impl_store( const OUString& sURL const SfxFilter* pFilter = pMedium->GetFilter(); if ( pFilter && aFilterName.equals( pFilter->GetFilterName() ) ) { - aArgHash.erase( aFilterString ); - aArgHash.erase( OUString( "URL" ) ); - - try + // #i119366# - If the former file saving with password, do not trying in StoreSelf anyway... + bool bFormerPassword = false; { - storeSelf( aArgHash.getAsConstPropertyValueList() ); - bSaved = sal_True; + uno::Sequence< beans::NamedValue > aOldEncryptionData; + if (GetEncryptionData_Impl( pMedium->GetItemSet(), aOldEncryptionData )) + { + bFormerPassword = true; + } } - catch( const lang::IllegalArgumentException& ) + if ( !bFormerPassword ) { -#if HAVE_FEATURE_MULTIUSER_ENVIRONMENT - // some additional arguments do not allow to use saving, SaveAs should be done - // but only for normal documents, the shared documents would be overwritten in this case - // that would mean an information loss - // TODO/LATER: need a new interaction for this case - if ( m_pData->m_pObjectShell->IsDocShared() ) - { - m_pData->m_pObjectShell->AddLog( OUString( OSL_LOG_PREFIX "Can't store shared document!" ) ); - m_pData->m_pObjectShell->StoreLog(); + aArgHash.erase( aFilterString ); + aArgHash.erase( OUString( "URL" ) ); - Sequence< beans::NamedValue > aNewEncryptionData = aArgHash.getUnpackedValueOrDefault( OUString( "EncryptionData" ), Sequence< beans::NamedValue >() ); - if ( !aNewEncryptionData.getLength() ) + try + { + storeSelf( aArgHash.getAsConstPropertyValueList() ); + bSaved = sal_True; + } + catch( const lang::IllegalArgumentException& ) + { +#if HAVE_FEATURE_MULTIUSER_ENVIRONMENT + // some additional arguments do not allow to use saving, SaveAs should be done + // but only for normal documents, the shared documents would be overwritten in this case + // that would mean an information loss + // TODO/LATER: need a new interaction for this case + if ( m_pData->m_pObjectShell->IsDocShared() ) { - OUString aNewPassword = aArgHash.getUnpackedValueOrDefault( OUString( "Password" ), OUString() ); - aNewEncryptionData = ::comphelper::OStorageHelper::CreatePackageEncryptionData( aNewPassword ); - } + m_pData->m_pObjectShell->AddLog( OUString( OSL_LOG_PREFIX "Can't store shared document!" ) ); + m_pData->m_pObjectShell->StoreLog(); - Sequence< beans::NamedValue > aOldEncryptionData; - GetEncryptionData_Impl( pMedium->GetItemSet(), aOldEncryptionData ); + uno::Sequence< beans::NamedValue > aNewEncryptionData = aArgHash.getUnpackedValueOrDefault( OUString( "EncryptionData" ), uno::Sequence< beans::NamedValue >() ); + if ( !aNewEncryptionData.getLength() ) + { + OUString aNewPassword = aArgHash.getUnpackedValueOrDefault( OUString( "Password" ), OUString() ); + aNewEncryptionData = ::comphelper::OStorageHelper::CreatePackageEncryptionData( aNewPassword ); + } - if ( !aOldEncryptionData.getLength() && !aNewEncryptionData.getLength() ) - throw; - else - { - // if the password is changed a special error should be used in case of shared document - throw task::ErrorCodeIOException( OUString( "Cant change password for shared document." ), Reference< XInterface >(), ERRCODE_SFX_SHARED_NOPASSWORDCHANGE ); + uno::Sequence< beans::NamedValue > aOldEncryptionData; + GetEncryptionData_Impl( pMedium->GetItemSet(), aOldEncryptionData ); + + if ( !aOldEncryptionData.getLength() && !aNewEncryptionData.getLength() ) + throw; + else + { + // if the password is changed a special error should be used in case of shared document + throw task::ErrorCodeIOException( OUString( "Cant change password for shared document." ), uno::Reference< uno::XInterface >(), ERRCODE_SFX_SHARED_NOPASSWORDCHANGE ); + } } - } #endif + } } } } |