Kaydet (Commit) 9957730b authored tarafından Oliver-Rainer Wittmann's avatar Oliver-Rainer Wittmann

#119366# - assure that password can be removed from a document 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>
üst 9110bec2
...@@ -2919,6 +2919,9 @@ sal_Bool SfxObjectShell::PreDoSaveAs_Impl ...@@ -2919,6 +2919,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_PASSWORD ); pMergedParams->ClearItem( SID_PASSWORD );
// 119366 - As the SID_ENCRYPTIONDATA and SID_PASSWORD are using for setting passward 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 );
......
...@@ -2788,41 +2788,53 @@ void SfxBaseModel::impl_store( const ::rtl::OUString& sURL ...@@ -2788,41 +2788,53 @@ void SfxBaseModel::impl_store( const ::rtl::OUString& sURL
const SfxFilter* pFilter = pMedium->GetFilter(); const SfxFilter* pFilter = pMedium->GetFilter();
if ( pFilter && aFilterName.equals( pFilter->GetFilterName() ) ) if ( pFilter && aFilterName.equals( pFilter->GetFilterName() ) )
{ {
aArgHash.erase( aFilterString ); // 119366 - If the former file saving with password, do not trying in StoreSelf anyway...
aArgHash.erase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ) ); bool bFormerPassword = false;
try
{ {
storeSelf( aArgHash.getAsConstPropertyValueList() ); uno::Sequence< beans::NamedValue > aOldEncryptionData;
bSaved = sal_True; if (GetEncryptionData_Impl( pMedium->GetItemSet(), aOldEncryptionData ))
{
bFormerPassword = true;
}
} }
catch( const lang::IllegalArgumentException& ) if ( !bFormerPassword )
{ {
// some additional arguments do not allow to use saving, SaveAs should be done aArgHash.erase( aFilterString );
// but only for normal documents, the shared documents would be overwritten in this case aArgHash.erase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ) );
// 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( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't store shared document!" ) ) );
m_pData->m_pObjectShell->StoreLog();
uno::Sequence< beans::NamedValue > aNewEncryptionData = aArgHash.getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionData" ) ), uno::Sequence< beans::NamedValue >() ); try
if ( !aNewEncryptionData.getLength() ) {
storeSelf( aArgHash.getAsConstPropertyValueList() );
bSaved = sal_True;
}
catch( const lang::IllegalArgumentException& )
{
// 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() )
{ {
::rtl::OUString aNewPassword = aArgHash.getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Password" ) ), ::rtl::OUString() ); m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Can't store shared document!" ) ) );
aNewEncryptionData = ::comphelper::OStorageHelper::CreatePackageEncryptionData( aNewPassword ); m_pData->m_pObjectShell->StoreLog();
}
uno::Sequence< beans::NamedValue > aOldEncryptionData; uno::Sequence< beans::NamedValue > aNewEncryptionData = aArgHash.getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EncryptionData" ) ), uno::Sequence< beans::NamedValue >() );
GetEncryptionData_Impl( pMedium->GetItemSet(), aOldEncryptionData ); if ( !aNewEncryptionData.getLength() )
{
::rtl::OUString aNewPassword = aArgHash.getUnpackedValueOrDefault( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Password" ) ), ::rtl::OUString() );
aNewEncryptionData = ::comphelper::OStorageHelper::CreatePackageEncryptionData( aNewPassword );
}
if ( !aOldEncryptionData.getLength() && !aNewEncryptionData.getLength() ) uno::Sequence< beans::NamedValue > aOldEncryptionData;
throw; GetEncryptionData_Impl( pMedium->GetItemSet(), aOldEncryptionData );
else
{ if ( !aOldEncryptionData.getLength() && !aNewEncryptionData.getLength() )
// if the password is changed a special error should be used in case of shared document throw;
throw task::ErrorCodeIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cant change password for shared document." ) ), uno::Reference< uno::XInterface >(), ERRCODE_SFX_SHARED_NOPASSWORDCHANGE ); else
{
// if the password is changed a special error should be used in case of shared document
throw task::ErrorCodeIOException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Cant change password for shared document." ) ), uno::Reference< uno::XInterface >(), ERRCODE_SFX_SHARED_NOPASSWORDCHANGE );
}
} }
} }
} }
......
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