1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sfx2.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "sfx2/docmacromode.hxx" 32*cdf0e10cSrcweir #include "sfx2/signaturestate.hxx" 33*cdf0e10cSrcweir #include "sfx2/docfile.hxx" 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir /** === begin UNO includes === **/ 36*cdf0e10cSrcweir #include <com/sun/star/document/MacroExecMode.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/task/ErrorCodeRequest.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/task/DocumentMacroConfirmationRequest.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/task/InteractionClassification.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/security/XDocumentDigitalSignatures.hpp> 41*cdf0e10cSrcweir /** === end UNO includes === **/ 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir #include <comphelper/componentcontext.hxx> 44*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 45*cdf0e10cSrcweir #include <framework/interaction.hxx> 46*cdf0e10cSrcweir #include <osl/file.hxx> 47*cdf0e10cSrcweir #include <rtl/ref.hxx> 48*cdf0e10cSrcweir #include <unotools/securityoptions.hxx> 49*cdf0e10cSrcweir #include <svtools/sfxecode.hxx> 50*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 51*cdf0e10cSrcweir #include <tools/urlobj.hxx> 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir //........................................................................ 54*cdf0e10cSrcweir namespace sfx2 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir //........................................................................ 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir /** === begin UNO using === **/ 59*cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 60*cdf0e10cSrcweir using ::com::sun::star::task::XInteractionHandler; 61*cdf0e10cSrcweir using ::com::sun::star::uno::Any; 62*cdf0e10cSrcweir using ::com::sun::star::task::XInteractionHandler; 63*cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 64*cdf0e10cSrcweir using ::com::sun::star::task::XInteractionContinuation; 65*cdf0e10cSrcweir using ::com::sun::star::task::XInteractionRequest; 66*cdf0e10cSrcweir using ::com::sun::star::task::DocumentMacroConfirmationRequest; 67*cdf0e10cSrcweir using ::com::sun::star::task::ErrorCodeRequest; 68*cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 69*cdf0e10cSrcweir using ::com::sun::star::security::XDocumentDigitalSignatures; 70*cdf0e10cSrcweir using ::com::sun::star::security::DocumentSignatureInformation; 71*cdf0e10cSrcweir using ::com::sun::star::embed::XStorage; 72*cdf0e10cSrcweir using ::com::sun::star::task::InteractionClassification_QUERY; 73*cdf0e10cSrcweir using ::com::sun::star::document::XEmbeddedScripts; 74*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_SET_THROW; 75*cdf0e10cSrcweir using ::com::sun::star::script::XLibraryContainer; 76*cdf0e10cSrcweir using ::com::sun::star::container::XNameAccess; 77*cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW; 78*cdf0e10cSrcweir /** === end UNO using === **/ 79*cdf0e10cSrcweir namespace MacroExecMode = ::com::sun::star::document::MacroExecMode; 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir //==================================================================== 82*cdf0e10cSrcweir //= DocumentMacroMode_Data 83*cdf0e10cSrcweir //==================================================================== 84*cdf0e10cSrcweir struct DocumentMacroMode_Data 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir IMacroDocumentAccess& m_rDocumentAccess; 87*cdf0e10cSrcweir sal_Bool m_bMacroDisabledMessageShown; 88*cdf0e10cSrcweir sal_Bool m_bDocMacroDisabledMessageShown; 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir DocumentMacroMode_Data( IMacroDocumentAccess& rDocumentAccess ) 91*cdf0e10cSrcweir :m_rDocumentAccess( rDocumentAccess ) 92*cdf0e10cSrcweir ,m_bMacroDisabledMessageShown( sal_False ) 93*cdf0e10cSrcweir ,m_bDocMacroDisabledMessageShown( sal_False ) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir }; 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir //==================================================================== 99*cdf0e10cSrcweir //= helper 100*cdf0e10cSrcweir //==================================================================== 101*cdf0e10cSrcweir namespace 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir //................................................................ 104*cdf0e10cSrcweir void lcl_showGeneralSfxErrorOnce( const Reference< XInteractionHandler >& rxHandler, const sal_Int32 nSfxErrorCode, sal_Bool& rbAlreadyShown ) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir if ( rbAlreadyShown ) 107*cdf0e10cSrcweir return; 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir ErrorCodeRequest aErrorCodeRequest; 110*cdf0e10cSrcweir aErrorCodeRequest.ErrCode = nSfxErrorCode; 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir SfxMedium::CallApproveHandler( rxHandler, makeAny( aErrorCodeRequest ), sal_False ); 113*cdf0e10cSrcweir rbAlreadyShown = sal_True; 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir //................................................................ 117*cdf0e10cSrcweir void lcl_showMacrosDisabledError( const Reference< XInteractionHandler >& rxHandler, sal_Bool& rbAlreadyShown ) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir lcl_showGeneralSfxErrorOnce( rxHandler, ERRCODE_SFX_MACROS_SUPPORT_DISABLED, rbAlreadyShown ); 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir //................................................................ 123*cdf0e10cSrcweir void lcl_showDocumentMacrosDisabledError( const Reference< XInteractionHandler >& rxHandler, sal_Bool& rbAlreadyShown ) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir lcl_showGeneralSfxErrorOnce( rxHandler, ERRCODE_SFX_DOCUMENT_MACRO_DISABLED, rbAlreadyShown ); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir //................................................................ 129*cdf0e10cSrcweir sal_Bool lcl_showMacroWarning( const Reference< XInteractionHandler >& rxHandler, 130*cdf0e10cSrcweir const ::rtl::OUString& rDocumentLocation ) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir DocumentMacroConfirmationRequest aRequest; 133*cdf0e10cSrcweir aRequest.DocumentURL = rDocumentLocation; 134*cdf0e10cSrcweir return SfxMedium::CallApproveHandler( rxHandler, makeAny( aRequest ), sal_True ); 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir //==================================================================== 139*cdf0e10cSrcweir //= DocumentMacroMode 140*cdf0e10cSrcweir //==================================================================== 141*cdf0e10cSrcweir //-------------------------------------------------------------------- 142*cdf0e10cSrcweir DocumentMacroMode::DocumentMacroMode( IMacroDocumentAccess& rDocumentAccess ) 143*cdf0e10cSrcweir :m_pData( new DocumentMacroMode_Data( rDocumentAccess ) ) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir //-------------------------------------------------------------------- 148*cdf0e10cSrcweir DocumentMacroMode::~DocumentMacroMode() 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir //-------------------------------------------------------------------- 153*cdf0e10cSrcweir sal_Bool DocumentMacroMode::allowMacroExecution() 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir m_pData->m_rDocumentAccess.setCurrentMacroExecMode( MacroExecMode::ALWAYS_EXECUTE_NO_WARN ); 156*cdf0e10cSrcweir return sal_True; 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir //-------------------------------------------------------------------- 160*cdf0e10cSrcweir sal_Bool DocumentMacroMode::disallowMacroExecution() 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir m_pData->m_rDocumentAccess.setCurrentMacroExecMode( MacroExecMode::NEVER_EXECUTE ); 163*cdf0e10cSrcweir return sal_False; 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir //-------------------------------------------------------------------- 167*cdf0e10cSrcweir sal_Bool DocumentMacroMode::adjustMacroMode( const Reference< XInteractionHandler >& rxInteraction ) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir sal_uInt16 nMacroExecutionMode = m_pData->m_rDocumentAccess.getCurrentMacroExecMode(); 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir if ( SvtSecurityOptions().IsMacroDisabled() ) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir // no macro should be executed at all 174*cdf0e10cSrcweir lcl_showMacrosDisabledError( rxInteraction, m_pData->m_bMacroDisabledMessageShown ); 175*cdf0e10cSrcweir return disallowMacroExecution(); 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir // get setting from configuration if required 179*cdf0e10cSrcweir enum AutoConfirmation 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir eNoAutoConfirm, 182*cdf0e10cSrcweir eAutoConfirmApprove, 183*cdf0e10cSrcweir eAutoConfirmReject 184*cdf0e10cSrcweir }; 185*cdf0e10cSrcweir AutoConfirmation eAutoConfirm( eNoAutoConfirm ); 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir if ( ( nMacroExecutionMode == MacroExecMode::USE_CONFIG ) 188*cdf0e10cSrcweir || ( nMacroExecutionMode == MacroExecMode::USE_CONFIG_REJECT_CONFIRMATION ) 189*cdf0e10cSrcweir || ( nMacroExecutionMode == MacroExecMode::USE_CONFIG_APPROVE_CONFIRMATION ) 190*cdf0e10cSrcweir ) 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir SvtSecurityOptions aOpt; 193*cdf0e10cSrcweir switch ( aOpt.GetMacroSecurityLevel() ) 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir case 3: 196*cdf0e10cSrcweir nMacroExecutionMode = MacroExecMode::FROM_LIST_NO_WARN; 197*cdf0e10cSrcweir break; 198*cdf0e10cSrcweir case 2: 199*cdf0e10cSrcweir nMacroExecutionMode = MacroExecMode::FROM_LIST_AND_SIGNED_WARN; 200*cdf0e10cSrcweir break; 201*cdf0e10cSrcweir case 1: 202*cdf0e10cSrcweir nMacroExecutionMode = MacroExecMode::ALWAYS_EXECUTE; 203*cdf0e10cSrcweir break; 204*cdf0e10cSrcweir case 0: 205*cdf0e10cSrcweir nMacroExecutionMode = MacroExecMode::ALWAYS_EXECUTE_NO_WARN; 206*cdf0e10cSrcweir break; 207*cdf0e10cSrcweir default: 208*cdf0e10cSrcweir OSL_ENSURE( sal_False, "DocumentMacroMode::adjustMacroMode: unexpected macro security level!" ); 209*cdf0e10cSrcweir nMacroExecutionMode = MacroExecMode::NEVER_EXECUTE; 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir if ( nMacroExecutionMode == MacroExecMode::USE_CONFIG_REJECT_CONFIRMATION ) 213*cdf0e10cSrcweir eAutoConfirm = eAutoConfirmReject; 214*cdf0e10cSrcweir else if ( nMacroExecutionMode == MacroExecMode::USE_CONFIG_APPROVE_CONFIRMATION ) 215*cdf0e10cSrcweir eAutoConfirm = eAutoConfirmApprove; 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir if ( nMacroExecutionMode == MacroExecMode::NEVER_EXECUTE ) 219*cdf0e10cSrcweir return sal_False; 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir if ( nMacroExecutionMode == MacroExecMode::ALWAYS_EXECUTE_NO_WARN ) 222*cdf0e10cSrcweir return sal_True; 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir try 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir ::rtl::OUString sReferrer( m_pData->m_rDocumentAccess.getDocumentLocation() ); 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir // get document location from medium name and check whether it is a trusted one 229*cdf0e10cSrcweir // the service is created ohne document version, since it is not of interest here 230*cdf0e10cSrcweir ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() ); 231*cdf0e10cSrcweir Reference< XDocumentDigitalSignatures > xSignatures; 232*cdf0e10cSrcweir if ( aContext.createComponent( "com.sun.star.security.DocumentDigitalSignatures", xSignatures ) ) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir INetURLObject aURLReferer( sReferrer ); 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir ::rtl::OUString aLocation; 237*cdf0e10cSrcweir if ( aURLReferer.removeSegment() ) 238*cdf0e10cSrcweir aLocation = aURLReferer.GetMainURL( INetURLObject::NO_DECODE ); 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir if ( aLocation.getLength() && xSignatures->isLocationTrusted( aLocation ) ) 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir return allowMacroExecution(); 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir // at this point it is clear that the document is not in the secure location 247*cdf0e10cSrcweir if ( nMacroExecutionMode == MacroExecMode::FROM_LIST_NO_WARN ) 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir lcl_showDocumentMacrosDisabledError( rxInteraction, m_pData->m_bDocMacroDisabledMessageShown ); 250*cdf0e10cSrcweir return disallowMacroExecution(); 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir // check whether the document is signed with trusted certificate 254*cdf0e10cSrcweir if ( nMacroExecutionMode != MacroExecMode::FROM_LIST ) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir // the trusted macro check will also retrieve the signature state ( small optimization ) 257*cdf0e10cSrcweir sal_Bool bHasTrustedMacroSignature = m_pData->m_rDocumentAccess.hasTrustedScriptingSignature( nMacroExecutionMode != MacroExecMode::FROM_LIST_AND_SIGNED_NO_WARN ); 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir sal_uInt16 nSignatureState = m_pData->m_rDocumentAccess.getScriptingSignatureState(); 260*cdf0e10cSrcweir if ( nSignatureState == SIGNATURESTATE_SIGNATURES_BROKEN ) 261*cdf0e10cSrcweir { 262*cdf0e10cSrcweir // the signature is broken, no macro execution 263*cdf0e10cSrcweir if ( nMacroExecutionMode != MacroExecMode::FROM_LIST_AND_SIGNED_NO_WARN ) 264*cdf0e10cSrcweir m_pData->m_rDocumentAccess.showBrokenSignatureWarning( rxInteraction ); 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir return disallowMacroExecution(); 267*cdf0e10cSrcweir } 268*cdf0e10cSrcweir else if ( bHasTrustedMacroSignature ) 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir // there is trusted macro signature, allow macro execution 271*cdf0e10cSrcweir return allowMacroExecution(); 272*cdf0e10cSrcweir } 273*cdf0e10cSrcweir else if ( nSignatureState == SIGNATURESTATE_SIGNATURES_OK 274*cdf0e10cSrcweir || nSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED ) 275*cdf0e10cSrcweir { 276*cdf0e10cSrcweir // there is valid signature, but it is not from the trusted author 277*cdf0e10cSrcweir return disallowMacroExecution(); 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir // at this point it is clear that the document is neither in secure location nor signed with trusted certificate 282*cdf0e10cSrcweir if ( ( nMacroExecutionMode == MacroExecMode::FROM_LIST_AND_SIGNED_NO_WARN ) 283*cdf0e10cSrcweir || ( nMacroExecutionMode == MacroExecMode::FROM_LIST_AND_SIGNED_WARN ) 284*cdf0e10cSrcweir ) 285*cdf0e10cSrcweir { 286*cdf0e10cSrcweir if ( nMacroExecutionMode == MacroExecMode::FROM_LIST_AND_SIGNED_WARN ) 287*cdf0e10cSrcweir lcl_showDocumentMacrosDisabledError( rxInteraction, m_pData->m_bDocMacroDisabledMessageShown ); 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir return disallowMacroExecution(); 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir catch ( Exception& ) 293*cdf0e10cSrcweir { 294*cdf0e10cSrcweir if ( ( nMacroExecutionMode == MacroExecMode::FROM_LIST_NO_WARN ) 295*cdf0e10cSrcweir || ( nMacroExecutionMode == MacroExecMode::FROM_LIST_AND_SIGNED_WARN ) 296*cdf0e10cSrcweir || ( nMacroExecutionMode == MacroExecMode::FROM_LIST_AND_SIGNED_NO_WARN ) 297*cdf0e10cSrcweir ) 298*cdf0e10cSrcweir { 299*cdf0e10cSrcweir return disallowMacroExecution(); 300*cdf0e10cSrcweir } 301*cdf0e10cSrcweir } 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir // conformation is required 304*cdf0e10cSrcweir sal_Bool bSecure = sal_False; 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir if ( eAutoConfirm == eNoAutoConfirm ) 307*cdf0e10cSrcweir { 308*cdf0e10cSrcweir ::rtl::OUString sReferrer( m_pData->m_rDocumentAccess.getDocumentLocation() ); 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir ::rtl::OUString aSystemFileURL; 311*cdf0e10cSrcweir if ( osl::FileBase::getSystemPathFromFileURL( sReferrer, aSystemFileURL ) == osl::FileBase::E_None ) 312*cdf0e10cSrcweir sReferrer = aSystemFileURL; 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir bSecure = lcl_showMacroWarning( rxInteraction, sReferrer ); 315*cdf0e10cSrcweir } 316*cdf0e10cSrcweir else 317*cdf0e10cSrcweir bSecure = ( eAutoConfirm == eAutoConfirmApprove ); 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir return ( bSecure ? allowMacroExecution() : disallowMacroExecution() ); 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir //-------------------------------------------------------------------- 323*cdf0e10cSrcweir sal_Bool DocumentMacroMode::isMacroExecutionDisallowed() const 324*cdf0e10cSrcweir { 325*cdf0e10cSrcweir return m_pData->m_rDocumentAccess.getCurrentMacroExecMode() == MacroExecMode::NEVER_EXECUTE; 326*cdf0e10cSrcweir } 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir //-------------------------------------------------------------------- 329*cdf0e10cSrcweir sal_Bool DocumentMacroMode::hasMacroLibrary() const 330*cdf0e10cSrcweir { 331*cdf0e10cSrcweir sal_Bool bHasMacroLib = sal_False; 332*cdf0e10cSrcweir try 333*cdf0e10cSrcweir { 334*cdf0e10cSrcweir Reference< XEmbeddedScripts > xScripts( m_pData->m_rDocumentAccess.getEmbeddedDocumentScripts() ); 335*cdf0e10cSrcweir Reference< XLibraryContainer > xContainer; 336*cdf0e10cSrcweir if ( xScripts.is() ) 337*cdf0e10cSrcweir xContainer.set( xScripts->getBasicLibraries(), UNO_QUERY_THROW ); 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir if ( xContainer.is() ) 340*cdf0e10cSrcweir { 341*cdf0e10cSrcweir // a library container exists; check if it's empty 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir // if there are libraries except the "Standard" library 344*cdf0e10cSrcweir // we assume that they are not empty (because they have been created by the user) 345*cdf0e10cSrcweir if ( !xContainer->hasElements() ) 346*cdf0e10cSrcweir bHasMacroLib = sal_False; 347*cdf0e10cSrcweir else 348*cdf0e10cSrcweir { 349*cdf0e10cSrcweir ::rtl::OUString aStdLibName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) ); 350*cdf0e10cSrcweir Sequence< ::rtl::OUString > aElements = xContainer->getElementNames(); 351*cdf0e10cSrcweir if ( aElements.getLength() ) 352*cdf0e10cSrcweir { 353*cdf0e10cSrcweir if ( aElements.getLength() > 1 || !aElements[0].equals( aStdLibName ) ) 354*cdf0e10cSrcweir bHasMacroLib = sal_True; 355*cdf0e10cSrcweir else 356*cdf0e10cSrcweir { 357*cdf0e10cSrcweir // usually a "Standard" library is always present (design) 358*cdf0e10cSrcweir // for this reason we must check if it's empty 359*cdf0e10cSrcweir // 360*cdf0e10cSrcweir // Note: Since #i73229#, this is not true anymore. There's no default 361*cdf0e10cSrcweir // "Standard" lib anymore. Wouldn't it be time to get completely 362*cdf0e10cSrcweir // rid of the "Standard" thingie - this shouldn't be necessary 363*cdf0e10cSrcweir // anymore, should it? 364*cdf0e10cSrcweir // 2007-01-25 / frank.schoenheit@sun.com 365*cdf0e10cSrcweir Reference < XNameAccess > xLib; 366*cdf0e10cSrcweir Any aAny = xContainer->getByName( aStdLibName ); 367*cdf0e10cSrcweir aAny >>= xLib; 368*cdf0e10cSrcweir if ( xLib.is() ) 369*cdf0e10cSrcweir bHasMacroLib = xLib->hasElements(); 370*cdf0e10cSrcweir } 371*cdf0e10cSrcweir } 372*cdf0e10cSrcweir } 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir } 375*cdf0e10cSrcweir catch( const Exception& ) 376*cdf0e10cSrcweir { 377*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 378*cdf0e10cSrcweir } 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir return bHasMacroLib; 381*cdf0e10cSrcweir } 382*cdf0e10cSrcweir 383*cdf0e10cSrcweir //-------------------------------------------------------------------- 384*cdf0e10cSrcweir sal_Bool DocumentMacroMode::storageHasMacros( const Reference< XStorage >& rxStorage ) 385*cdf0e10cSrcweir { 386*cdf0e10cSrcweir sal_Bool bHasMacros = sal_False; 387*cdf0e10cSrcweir if ( rxStorage.is() ) 388*cdf0e10cSrcweir { 389*cdf0e10cSrcweir try 390*cdf0e10cSrcweir { 391*cdf0e10cSrcweir static const ::rtl::OUString s_sBasicStorageName( ::rtl::OUString::intern( RTL_CONSTASCII_USTRINGPARAM( "Basic" ) ) ); 392*cdf0e10cSrcweir static const ::rtl::OUString s_sScriptsStorageName( ::rtl::OUString::intern( RTL_CONSTASCII_USTRINGPARAM( "Scripts" ) ) ); 393*cdf0e10cSrcweir 394*cdf0e10cSrcweir bHasMacros =( ( rxStorage->hasByName( s_sBasicStorageName ) 395*cdf0e10cSrcweir && rxStorage->isStorageElement( s_sBasicStorageName ) 396*cdf0e10cSrcweir ) 397*cdf0e10cSrcweir || ( rxStorage->hasByName( s_sScriptsStorageName ) 398*cdf0e10cSrcweir && rxStorage->isStorageElement( s_sScriptsStorageName ) 399*cdf0e10cSrcweir ) 400*cdf0e10cSrcweir ); 401*cdf0e10cSrcweir } 402*cdf0e10cSrcweir catch ( const Exception& ) 403*cdf0e10cSrcweir { 404*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir } 407*cdf0e10cSrcweir return bHasMacros; 408*cdf0e10cSrcweir } 409*cdf0e10cSrcweir 410*cdf0e10cSrcweir //-------------------------------------------------------------------- 411*cdf0e10cSrcweir sal_Bool DocumentMacroMode::checkMacrosOnLoading( const Reference< XInteractionHandler >& rxInteraction ) 412*cdf0e10cSrcweir { 413*cdf0e10cSrcweir sal_Bool bAllow = sal_False; 414*cdf0e10cSrcweir if ( SvtSecurityOptions().IsMacroDisabled() ) 415*cdf0e10cSrcweir { 416*cdf0e10cSrcweir // no macro should be executed at all 417*cdf0e10cSrcweir bAllow = disallowMacroExecution(); 418*cdf0e10cSrcweir } 419*cdf0e10cSrcweir else 420*cdf0e10cSrcweir { 421*cdf0e10cSrcweir if ( m_pData->m_rDocumentAccess.documentStorageHasMacros() || hasMacroLibrary() ) 422*cdf0e10cSrcweir { 423*cdf0e10cSrcweir bAllow = adjustMacroMode( rxInteraction ); 424*cdf0e10cSrcweir } 425*cdf0e10cSrcweir else if ( !isMacroExecutionDisallowed() ) 426*cdf0e10cSrcweir { 427*cdf0e10cSrcweir // if macros will be added by the user later, the security check is obsolete 428*cdf0e10cSrcweir bAllow = allowMacroExecution(); 429*cdf0e10cSrcweir } 430*cdf0e10cSrcweir } 431*cdf0e10cSrcweir return bAllow; 432*cdf0e10cSrcweir } 433*cdf0e10cSrcweir 434*cdf0e10cSrcweir //........................................................................ 435*cdf0e10cSrcweir } // namespace sfx2 436*cdf0e10cSrcweir //........................................................................ 437