summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorMikhail Voytenko <mav@openoffice.org>2010-06-03 00:10:45 +0200
committerMikhail Voytenko <mav@openoffice.org>2010-06-03 00:10:45 +0200
commit54506d201e055ec183c6a33fec701aa67fe912ed (patch)
tree54d4fa3c0d0151e46f0cba521975072ccc3112d6 /sfx2
parentf54b0698c46d9d33b4ae75d3873f55e8b15367d8 (diff)
tl78: #i110383# password to modify support for binary types only
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/inc/sfx2/docfile.hxx2
-rw-r--r--sfx2/inc/sfx2/objsh.hxx4
-rw-r--r--sfx2/inc/sfx2/sfxsids.hrc2
-rw-r--r--sfx2/sdi/sfx.sdi4
-rw-r--r--sfx2/source/dialog/filedlghelper.cxx8
-rw-r--r--sfx2/source/doc/docfile.cxx17
-rw-r--r--sfx2/source/doc/guisaveas.cxx34
-rw-r--r--sfx2/source/doc/objcont.cxx4
-rw-r--r--sfx2/source/doc/sfxbasemodel.cxx14
-rw-r--r--sfx2/source/inc/objshimp.hxx2
-rw-r--r--sfx2/source/view/viewfrm.cxx4
11 files changed, 43 insertions, 52 deletions
diff --git a/sfx2/inc/sfx2/docfile.hxx b/sfx2/inc/sfx2/docfile.hxx
index f19d2845fa..cd43e0989d 100644
--- a/sfx2/inc/sfx2/docfile.hxx
+++ b/sfx2/inc/sfx2/docfile.hxx
@@ -328,7 +328,7 @@ public:
static sal_Bool CallApproveHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& xHandler, ::com::sun::star::uno::Any aRequest, sal_Bool bAllowAbort );
static sal_Bool SetWritableForUserOnly( const ::rtl::OUString& aURL );
- static sal_uInt16 CreatePasswordToModifyHash( const ::rtl::OUString& aPasswd, sal_Bool bMSType );
+ static sal_uInt32 CreatePasswordToModifyHash( const ::rtl::OUString& aPasswd, sal_Bool bWriter );
};
SV_DECL_IMPL_REF( SfxMedium )
diff --git a/sfx2/inc/sfx2/objsh.hxx b/sfx2/inc/sfx2/objsh.hxx
index 111b91f758..4c133689cd 100644
--- a/sfx2/inc/sfx2/objsh.hxx
+++ b/sfx2/inc/sfx2/objsh.hxx
@@ -437,8 +437,8 @@ public:
void SetSaveVersionOnClose( sal_Bool bSet );
void ResetFromTemplate( const String& rTemplateName, const String& rFileName );
- sal_uInt16 GetModifyPasswordHash() const;
- sal_Bool SetModifyPasswordHash( sal_uInt16 nHash );
+ sal_uInt32 GetModifyPasswordHash() const;
+ sal_Bool SetModifyPasswordHash( sal_uInt32 nHash );
static sal_uInt32 HandleFilter( SfxMedium* pMedium, SfxObjectShell* pDoc );
diff --git a/sfx2/inc/sfx2/sfxsids.hrc b/sfx2/inc/sfx2/sfxsids.hrc
index fcc821f71f..ca5ee9fba1 100644
--- a/sfx2/inc/sfx2/sfxsids.hrc
+++ b/sfx2/inc/sfx2/sfxsids.hrc
@@ -306,7 +306,7 @@
#define SID_ACTIVATE_STYLE_APPLY (SID_SFX_START + 1715)
#define SID_FONT_NAME (SID_SFX_START + 1716)
#define SID_DEFAULTFILENAME (SID_SFX_START + 1717)
-#define SID_PASSWORDTOMODIFYHASH (SID_SFX_START + 1718)
+#define SID_MODIFYPASSWORDHASH (SID_SFX_START + 1718)
#define SID_RECOMMENDREADONLY (SID_SFX_START + 1719)
#define SID_SFX_free_START (SID_SFX_START + 1720)
#define SID_SFX_free_END (SID_SFX_START + 3999)
diff --git a/sfx2/sdi/sfx.sdi b/sfx2/sdi/sfx.sdi
index fcefd7bacb..13cfa2e531 100644
--- a/sfx2/sdi/sfx.sdi
+++ b/sfx2/sdi/sfx.sdi
@@ -3594,7 +3594,7 @@ SfxVoidItem MacroOrganizer SID_MACROORGANIZER
]
//--------------------------------------------------------------------------
-SfxUInt16Item PasswordToModifyHash SID_PASSWORDTOMODIFYHASH
+SfxUInt16Item PasswordToModifyHash SID_MODIFYPASSWORDHASH
[
/* flags: */
@@ -5317,7 +5317,7 @@ SfxBoolItem SaveAll SID_SAVEDOCS
//--------------------------------------------------------------------------
SfxBoolItem SaveAs SID_SAVEASDOC
-(SfxStringItem URL SID_FILE_NAME,SfxStringItem FilterName SID_FILTER_NAME,SfxStringItem Password SID_PASSWORD,SfxStringItem FilterOptions SID_FILE_FILTEROPTIONS,SfxStringItem VersionComment SID_DOCINFO_COMMENTS,SfxStringItem VersionAuthor SID_DOCINFO_AUTHOR,SfxBoolItem Overwrite SID_OVERWRITE,SfxBoolItem Unpacked SID_UNPACK,SfxBoolItem SaveTo SID_SAVETO)
+(SfxStringItem URL SID_FILE_NAME,SfxStringItem FilterName SID_FILTER_NAME,SfxStringItem Password SID_PASSWORD,SfxStringItem FilterOptions SID_FILE_FILTEROPTIONS,SfxStringItem VersionComment SID_DOCINFO_COMMENTS,SfxStringItem VersionAuthor SID_DOCINFO_AUTHOR,SfxBoolItem Overwrite SID_OVERWRITE,SfxBoolItem Unpacked SID_UNPACK,SfxBoolItem SaveTo SID_SAVETO,SfxInt32Item ModifyPasswordHash SID_MODIFYPASSWORDHASH)
[
/* flags: */
AutoUpdate = FALSE,
diff --git a/sfx2/source/dialog/filedlghelper.cxx b/sfx2/source/dialog/filedlghelper.cxx
index 337e9bc634..87fa88484c 100644
--- a/sfx2/source/dialog/filedlghelper.cxx
+++ b/sfx2/source/dialog/filedlghelper.cxx
@@ -1528,7 +1528,7 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList,
mbPwdCheckBoxState = ( pPassItem != NULL );
// in case the document has password to modify, the dialog should be shown
- SFX_ITEMSET_ARG( rpSet, pPassToModifyItem, SfxUInt16Item, SID_PASSWORDTOMODIFYHASH, FALSE );
+ SFX_ITEMSET_ARG( rpSet, pPassToModifyItem, SfxUInt32Item, SID_MODIFYPASSWORDHASH, FALSE );
mbPwdCheckBoxState |= ( pPassToModifyItem && pPassToModifyItem->GetValue() );
}
@@ -1541,7 +1541,7 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList,
// the password will be set in case user decide so
rpSet->ClearItem( SID_PASSWORD );
rpSet->ClearItem( SID_RECOMMENDREADONLY );
- rpSet->ClearItem( SID_PASSWORDTOMODIFYHASH );
+ rpSet->ClearItem( SID_MODIFYPASSWORDHASH );
}
@@ -1660,9 +1660,9 @@ ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList,
rpSet->Put( SfxBoolItem( SID_RECOMMENDREADONLY, sal_True ) );
// the empty password has 0 as Hash
- sal_uInt16 nHash = SfxMedium::CreatePasswordToModifyHash( pPasswordRequest->getPasswordToModify(), bMSType );
+ sal_uInt16 nHash = SfxMedium::CreatePasswordToModifyHash( pPasswordRequest->getPasswordToModify(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextDocument" ) ).equals( pCurrentFilter->GetServiceName() ) );
if ( nHash )
- rpSet->Put( SfxUInt16Item( SID_PASSWORDTOMODIFYHASH, nHash ) );
+ rpSet->Put( SfxInt32Item( SID_MODIFYPASSWORDHASH, (sal_Int32)nHash ) );
}
else
return ERRCODE_ABORT;
diff --git a/sfx2/source/doc/docfile.cxx b/sfx2/source/doc/docfile.cxx
index 4c7b9f91dc..43d98d1c04 100644
--- a/sfx2/source/doc/docfile.cxx
+++ b/sfx2/source/doc/docfile.cxx
@@ -2576,15 +2576,20 @@ void SfxMedium::SetOrigFilter_Impl( const SfxFilter* pOrigFilter )
//------------------------------------------------------------------
-sal_uInt16 SfxMedium::CreatePasswordToModifyHash( const ::rtl::OUString& aPasswd, sal_Bool bMSType )
+sal_uInt32 SfxMedium::CreatePasswordToModifyHash( const ::rtl::OUString& aPasswd, sal_Bool bWriter )
{
- sal_uInt16 nHash = 0;
+ sal_uInt32 nHash = 0;
if ( aPasswd.getLength() )
{
- rtl_TextEncoding nEncoding = RTL_TEXTENCODING_UTF8;
- if ( bMSType )
+ if ( bWriter )
{
+ nHash = ::comphelper::DocPasswordHelper::GetWordHashAsUINT32( aPasswd );
+ }
+ else
+ {
+ rtl_TextEncoding nEncoding = RTL_TEXTENCODING_UTF8;
+
// if the MS-filter should be used
// use the inconsistent algorithm to find the encoding specified by MS
nEncoding = osl_getThreadTextEncoding();
@@ -2612,9 +2617,9 @@ sal_uInt16 SfxMedium::CreatePasswordToModifyHash( const ::rtl::OUString& aPasswd
nEncoding = RTL_TEXTENCODING_MS_1250;
break;
}
- }
- nHash = ::comphelper::DocPasswordHelper::GetXLHashAsUINT16( aPasswd, nEncoding );
+ nHash = ::comphelper::DocPasswordHelper::GetXLHashAsUINT16( aPasswd, nEncoding );
+ }
}
return nHash;
diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx
index b8e775801a..534cccdcd4 100644
--- a/sfx2/source/doc/guisaveas.cxx
+++ b/sfx2/source/doc/guisaveas.cxx
@@ -180,18 +180,13 @@ class DocumentSettingsGuard
{
uno::Reference< beans::XPropertySet > m_xDocumentSettings;
sal_Bool m_bPreserveReadOnly;
- sal_uInt16 m_nPreserveHash;
-
sal_Bool m_bReadOnlySupported;
- sal_Bool m_bModifyPasswordHashSupported;
sal_Bool m_bRestoreSettings;
public:
- DocumentSettingsGuard( const uno::Reference< frame::XModel >& xModel, sal_Bool bReadOnly, sal_uInt16 nHash, sal_Bool bRestore )
+ DocumentSettingsGuard( const uno::Reference< frame::XModel >& xModel, sal_Bool bReadOnly, sal_Bool bRestore )
: m_bPreserveReadOnly( sal_False )
- , m_nPreserveHash( 0 )
, m_bReadOnlySupported( sal_False )
- , m_bModifyPasswordHashSupported( sal_False )
, m_bRestoreSettings( bRestore )
{
try
@@ -203,7 +198,6 @@ public:
uno::UNO_QUERY_THROW );
::rtl::OUString aLoadReadonlyString( RTL_CONSTASCII_USTRINGPARAM( "LoadReadonly" ) );
- ::rtl::OUString aModifyPasswordHashString( RTL_CONSTASCII_USTRINGPARAM( "ModifyPasswordHash" ) );
try
{
@@ -213,20 +207,11 @@ public:
}
catch( uno::Exception& )
{}
-
- try
- {
- m_xDocumentSettings->getPropertyValue( aModifyPasswordHashString ) >>= m_nPreserveHash;
- m_xDocumentSettings->setPropertyValue( aModifyPasswordHashString, uno::makeAny( nHash ) );
- m_bModifyPasswordHashSupported = sal_True;
- }
- catch( uno::Exception& )
- {}
}
catch( uno::Exception& )
{}
- if ( ( bReadOnly && !m_bReadOnlySupported ) || ( nHash && !m_bModifyPasswordHashSupported ) )
+ if ( ( bReadOnly && !m_bReadOnlySupported ) )
throw uno::RuntimeException(); // the user could provide the data, so it must be stored
}
@@ -235,15 +220,11 @@ public:
if ( m_bRestoreSettings )
{
::rtl::OUString aLoadReadonlyString( RTL_CONSTASCII_USTRINGPARAM( "LoadReadonly" ) );
- ::rtl::OUString aModifyPasswordHashString( RTL_CONSTASCII_USTRINGPARAM( "ModifyPasswordHash" ) );
try
{
if ( m_bReadOnlySupported )
m_xDocumentSettings->setPropertyValue( aLoadReadonlyString, uno::makeAny( m_bPreserveReadOnly ) );
-
- if ( m_bModifyPasswordHashSupported )
- m_xDocumentSettings->setPropertyValue( aModifyPasswordHashString, uno::makeAny( m_nPreserveHash ) );
}
catch( uno::Exception& )
{
@@ -272,7 +253,6 @@ class ModelData_Impl
::comphelper::SequenceAsHashMap m_aMediaDescrHM;
sal_Bool m_bRecommendReadOnly;
- sal_uInt16 m_nPasswordToModifyHash;
public:
ModelData_Impl( SfxStoringHelper& aOwner,
@@ -291,7 +271,6 @@ public:
::comphelper::SequenceAsHashMap& GetMediaDescr() { return m_aMediaDescrHM; }
sal_Bool IsRecommendReadOnly() { return m_bRecommendReadOnly; }
- sal_uInt16 GetPasswordToModifyHash() { return m_nPasswordToModifyHash; }
const ::comphelper::SequenceAsHashMap& GetDocProps();
@@ -346,8 +325,6 @@ ModelData_Impl::ModelData_Impl( SfxStoringHelper& aOwner,
, m_pModulePropsHM( NULL )
, m_aMediaDescrHM( aMediaDescr )
, m_bRecommendReadOnly( sal_False )
-, m_nPasswordToModifyHash( 0 )
-
{
CheckInteractionHandler();
}
@@ -1018,11 +995,6 @@ sal_Bool ModelData_Impl::OutputFileDialog( sal_Int8 nStoreMode,
m_bRecommendReadOnly = ( pRecommendReadOnly && pRecommendReadOnly->GetValue() );
pDialogParams->ClearItem( SID_RECOMMENDREADONLY );
- SFX_ITEMSET_ARG( pDialogParams, pPassToModifyItem, SfxUInt16Item, SID_PASSWORDTOMODIFYHASH, sal_False );
- if ( pPassToModifyItem )
- m_nPasswordToModifyHash = pPassToModifyItem->GetValue();
- pDialogParams->ClearItem( SID_PASSWORDTOMODIFYHASH );
-
uno::Sequence< beans::PropertyValue > aPropsFromDialog;
TransformItems( nSlotID, *pDialogParams, aPropsFromDialog, NULL );
GetMediaDescr() << aPropsFromDialog;
@@ -1607,7 +1579,7 @@ sal_Bool SfxStoringHelper::GUIStoreModel( const uno::Reference< frame::XModel >&
// store the document and handle it's docinfo
SvtSaveOptions aOptions;
- DocumentSettingsGuard aSettingsGuard( aModelData.GetModel(), aModelData.IsRecommendReadOnly(), aModelData.GetPasswordToModifyHash(), nStoreMode & EXPORT_REQUESTED );
+ DocumentSettingsGuard aSettingsGuard( aModelData.GetModel(), aModelData.IsRecommendReadOnly(), nStoreMode & EXPORT_REQUESTED );
if ( aOptions.IsDocInfoSave()
&& ( !aModelData.GetStorable()->hasLocation()
diff --git a/sfx2/source/doc/objcont.cxx b/sfx2/source/doc/objcont.cxx
index 46435f6b90..1066149e50 100644
--- a/sfx2/source/doc/objcont.cxx
+++ b/sfx2/source/doc/objcont.cxx
@@ -1242,12 +1242,12 @@ void SfxObjectShell::SetSaveVersionOnClose( sal_Bool bNew )
pImp->bSaveVersionOnClose = bNew;
}
-sal_uInt16 SfxObjectShell::GetModifyPasswordHash() const
+sal_uInt32 SfxObjectShell::GetModifyPasswordHash() const
{
return pImp->m_nModifyPasswordHash;
}
-sal_Bool SfxObjectShell::SetModifyPasswordHash( sal_uInt16 nHash )
+sal_Bool SfxObjectShell::SetModifyPasswordHash( sal_uInt32 nHash )
{
// Commented out before the solution for Saving process is found
// if ( ( !IsReadOnly() && !IsReadOnlyUI() )
diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx
index 7a5f630659..d253cd8741 100644
--- a/sfx2/source/doc/sfxbasemodel.cxx
+++ b/sfx2/source/doc/sfxbasemodel.cxx
@@ -74,6 +74,7 @@
#include <svl/itemset.hxx>
#include <svl/stritem.hxx>
#include <svl/eitem.hxx>
+#include <svl/intitem.hxx>
#include <basic/sbx.hxx>
#include <basic/sbuno.hxx>
#include <tools/urlobj.hxx>
@@ -2731,6 +2732,12 @@ void SfxBaseModel::impl_store( const ::rtl::OUString& sURL
uno::Reference< uno::XInterface >() );
}
+ SFX_ITEMSET_ARG( aParams, pModifyPasswordHashItem, SfxInt32Item, SID_MODIFYPASSWORDHASH, sal_False );
+ sal_uInt32 nModifyPasswordHash = pModifyPasswordHashItem ? pModifyPasswordHashItem->GetValue() : 0;
+ aParams->ClearItem( SID_MODIFYPASSWORDHASH );
+ sal_uInt32 nOldModifyPasswordHash = m_pData->m_pObjectShell->GetModifyPasswordHash();
+ m_pData->m_pObjectShell->SetModifyPasswordHash( nModifyPasswordHash );
+
// since saving a document modifies its DocumentInfo, the current
// DocumentInfo must be saved on "SaveTo", so it can be restored
// after saving
@@ -2809,10 +2816,14 @@ void SfxBaseModel::impl_store( const ::rtl::OUString& sURL
if ( !bSaveTo )
{
m_pData->m_aPreusedFilterName = GetMediumFilterName_Impl();
+ m_pData->m_pObjectShell->SetModifyPasswordEntered();
+
SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVEASDOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVEASDOCDONE), m_pData->m_pObjectShell ) );
}
else
{
+ m_pData->m_pObjectShell->SetModifyPasswordHash( nOldModifyPasswordHash );
+
SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_SAVETODOCDONE, GlobalEventConfig::GetEventName(STR_EVENT_SAVETODOCDONE), m_pData->m_pObjectShell ) );
}
}
@@ -2822,6 +2833,9 @@ void SfxBaseModel::impl_store( const ::rtl::OUString& sURL
m_pData->m_pObjectShell->AddLog( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX "Storing failed!" ) ) );
m_pData->m_pObjectShell->StoreLog();
+ m_pData->m_pObjectShell->SetModifyPasswordHash( nOldModifyPasswordHash );
+
+
SFX_APP()->NotifyEvent( SfxEventHint( bSaveTo ? SFX_EVENT_SAVETODOCFAILED : SFX_EVENT_SAVEASDOCFAILED, GlobalEventConfig::GetEventName( bSaveTo ? STR_EVENT_SAVETODOCFAILED : STR_EVENT_SAVEASDOCFAILED),
m_pData->m_pObjectShell ) );
diff --git a/sfx2/source/inc/objshimp.hxx b/sfx2/source/inc/objshimp.hxx
index 3290ef1e38..a5e3435568 100644
--- a/sfx2/source/inc/objshimp.hxx
+++ b/sfx2/source/inc/objshimp.hxx
@@ -149,7 +149,7 @@ struct SfxObjectShell_Impl : public ::sfx2::IMacroDocumentAccess
sal_Bool m_bIncomplEncrWarnShown;
- sal_uInt16 m_nModifyPasswordHash;
+ sal_uInt32 m_nModifyPasswordHash;
sal_Bool m_bModifyPasswordEntered;
SfxObjectShell_Impl( SfxObjectShell& _rDocShell );
diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx
index eb51ae1213..ddf97635a0 100644
--- a/sfx2/source/view/viewfrm.cxx
+++ b/sfx2/source/view/viewfrm.cxx
@@ -170,7 +170,7 @@ TYPEINIT1(SfxViewFrameItem, SfxPoolItem);
//=========================================================================
//-------------------------------------------------------------------------
-static sal_Bool AskPasswordToModify_Impl( const uno::Reference< task::XInteractionHandler >& xHandler, const ::rtl::OUString& aPath, const SfxFilter* pFilter, sal_uInt16 nPasswordHash )
+static sal_Bool AskPasswordToModify_Impl( const uno::Reference< task::XInteractionHandler >& xHandler, const ::rtl::OUString& aPath, const SfxFilter* pFilter, sal_uInt32 nPasswordHash )
{
sal_Bool bResult = !nPasswordHash;
@@ -196,7 +196,7 @@ static sal_Bool AskPasswordToModify_Impl( const uno::Reference< task::XInteracti
xHandler->handle( rRequest );
if ( pPasswordRequest->isPassword() )
- bResult = ( SfxMedium::CreatePasswordToModifyHash( pPasswordRequest->getPasswordToModify(), bMSType ) == nPasswordHash );
+ bResult = ( SfxMedium::CreatePasswordToModifyHash( pPasswordRequest->getPasswordToModify(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextDocument" ) ).equals( pFilter->GetServiceName() ) ) == nPasswordHash );
else
bCancel = sal_True;