Kaydet (Commit) cdfad2db authored tarafından Oliver-Rainer Wittmann's avatar Oliver-Rainer Wittmann Kaydeden (comit) Caolán McNamara

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 9957730b)

Conflicts:
	sfx2/source/doc/sfxbasemodel.cxx

Change-Id: I93bfdd7f32671171f1b219f9fd2dbeac30a92254
üst 4314e654
...@@ -2749,6 +2749,9 @@ sal_Bool SfxObjectShell::PreDoSaveAs_Impl ...@@ -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 ) // 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_ENCRYPTIONDATA );
pMergedParams->ClearItem( SID_PASSWORD ); 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_DOCINFO_TITLE );
pMergedParams->ClearItem( SID_INPUTSTREAM ); pMergedParams->ClearItem( SID_INPUTSTREAM );
......
...@@ -2949,6 +2949,17 @@ void SfxBaseModel::impl_store( const OUString& sURL ...@@ -2949,6 +2949,17 @@ void SfxBaseModel::impl_store( const OUString& sURL
{ {
const SfxFilter* pFilter = pMedium->GetFilter(); const SfxFilter* pFilter = pMedium->GetFilter();
if ( pFilter && aFilterName.equals( pFilter->GetFilterName() ) ) if ( pFilter && aFilterName.equals( pFilter->GetFilterName() ) )
{
// #i119366# - If the former file saving with password, do not trying in StoreSelf anyway...
bool bFormerPassword = false;
{
uno::Sequence< beans::NamedValue > aOldEncryptionData;
if (GetEncryptionData_Impl( pMedium->GetItemSet(), aOldEncryptionData ))
{
bFormerPassword = true;
}
}
if ( !bFormerPassword )
{ {
aArgHash.erase( aFilterString ); aArgHash.erase( aFilterString );
aArgHash.erase( OUString( "URL" ) ); aArgHash.erase( OUString( "URL" ) );
...@@ -2970,14 +2981,14 @@ void SfxBaseModel::impl_store( const OUString& sURL ...@@ -2970,14 +2981,14 @@ void SfxBaseModel::impl_store( const OUString& sURL
m_pData->m_pObjectShell->AddLog( OUString( OSL_LOG_PREFIX "Can't store shared document!" ) ); m_pData->m_pObjectShell->AddLog( OUString( OSL_LOG_PREFIX "Can't store shared document!" ) );
m_pData->m_pObjectShell->StoreLog(); m_pData->m_pObjectShell->StoreLog();
Sequence< beans::NamedValue > aNewEncryptionData = aArgHash.getUnpackedValueOrDefault( OUString( "EncryptionData" ), Sequence< beans::NamedValue >() ); uno::Sequence< beans::NamedValue > aNewEncryptionData = aArgHash.getUnpackedValueOrDefault( OUString( "EncryptionData" ), uno::Sequence< beans::NamedValue >() );
if ( !aNewEncryptionData.getLength() ) if ( !aNewEncryptionData.getLength() )
{ {
OUString aNewPassword = aArgHash.getUnpackedValueOrDefault( OUString( "Password" ), OUString() ); OUString aNewPassword = aArgHash.getUnpackedValueOrDefault( OUString( "Password" ), OUString() );
aNewEncryptionData = ::comphelper::OStorageHelper::CreatePackageEncryptionData( aNewPassword ); aNewEncryptionData = ::comphelper::OStorageHelper::CreatePackageEncryptionData( aNewPassword );
} }
Sequence< beans::NamedValue > aOldEncryptionData; uno::Sequence< beans::NamedValue > aOldEncryptionData;
GetEncryptionData_Impl( pMedium->GetItemSet(), aOldEncryptionData ); GetEncryptionData_Impl( pMedium->GetItemSet(), aOldEncryptionData );
if ( !aOldEncryptionData.getLength() && !aNewEncryptionData.getLength() ) if ( !aOldEncryptionData.getLength() && !aNewEncryptionData.getLength() )
...@@ -2985,7 +2996,7 @@ void SfxBaseModel::impl_store( const OUString& sURL ...@@ -2985,7 +2996,7 @@ void SfxBaseModel::impl_store( const OUString& sURL
else else
{ {
// if the password is changed a special error should be used in case of shared document // 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 ); throw task::ErrorCodeIOException( OUString( "Cant change password for shared document." ), uno::Reference< uno::XInterface >(), ERRCODE_SFX_SHARED_NOPASSWORDCHANGE );
} }
} }
#endif #endif
...@@ -2994,6 +3005,7 @@ void SfxBaseModel::impl_store( const OUString& sURL ...@@ -2994,6 +3005,7 @@ void SfxBaseModel::impl_store( const OUString& sURL
} }
} }
} }
}
if ( !bSaved && m_pData->m_pObjectShell ) if ( !bSaved && m_pData->m_pObjectShell )
{ {
......
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