LCOV - code coverage report
Current view: top level - sfx2/source/doc - docmacromode.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 70 164 42.7 %
Date: 2012-08-25 Functions: 9 14 64.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 73 311 23.5 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : 
      21                 :            : #include "sfx2/docmacromode.hxx"
      22                 :            : #include "sfx2/signaturestate.hxx"
      23                 :            : #include "sfx2/docfile.hxx"
      24                 :            : 
      25                 :            : #include <com/sun/star/document/MacroExecMode.hpp>
      26                 :            : #include <com/sun/star/task/ErrorCodeRequest.hpp>
      27                 :            : #include <com/sun/star/task/DocumentMacroConfirmationRequest.hpp>
      28                 :            : #include <com/sun/star/task/InteractionClassification.hpp>
      29                 :            : #include <com/sun/star/security/XDocumentDigitalSignatures.hpp>
      30                 :            : #include <com/sun/star/script/XLibraryQueryExecutable.hpp>
      31                 :            : #include <com/sun/star/script/vba/XVBACompatibility.hpp>
      32                 :            : 
      33                 :            : #include <comphelper/componentcontext.hxx>
      34                 :            : #include <comphelper/processfactory.hxx>
      35                 :            : #include <framework/interaction.hxx>
      36                 :            : #include <osl/file.hxx>
      37                 :            : #include <rtl/ref.hxx>
      38                 :            : #include <unotools/securityoptions.hxx>
      39                 :            : #include <svtools/sfxecode.hxx>
      40                 :            : #include <tools/diagnose_ex.h>
      41                 :            : #include <tools/urlobj.hxx>
      42                 :            : 
      43                 :            : //........................................................................
      44                 :            : namespace sfx2
      45                 :            : {
      46                 :            : //........................................................................
      47                 :            : 
      48                 :            :     /** === begin UNO using === **/
      49                 :            :     using ::com::sun::star::uno::Reference;
      50                 :            :     using ::com::sun::star::task::XInteractionHandler;
      51                 :            :     using ::com::sun::star::uno::Any;
      52                 :            :     using ::com::sun::star::task::XInteractionHandler;
      53                 :            :     using ::com::sun::star::uno::Sequence;
      54                 :            :     using ::com::sun::star::task::XInteractionContinuation;
      55                 :            :     using ::com::sun::star::task::XInteractionRequest;
      56                 :            :     using ::com::sun::star::task::DocumentMacroConfirmationRequest;
      57                 :            :     using ::com::sun::star::task::ErrorCodeRequest;
      58                 :            :     using ::com::sun::star::uno::Exception;
      59                 :            :     using ::com::sun::star::security::XDocumentDigitalSignatures;
      60                 :            :     using ::com::sun::star::security::DocumentSignatureInformation;
      61                 :            :     using ::com::sun::star::embed::XStorage;
      62                 :            :     using ::com::sun::star::task::InteractionClassification_QUERY;
      63                 :            :     using ::com::sun::star::document::XEmbeddedScripts;
      64                 :            :     using ::com::sun::star::uno::UNO_SET_THROW;
      65                 :            :     using ::com::sun::star::script::XLibraryContainer;
      66                 :            :     using ::com::sun::star::script::XLibraryQueryExecutable;
      67                 :            :     using ::com::sun::star::script::vba::XVBACompatibility;
      68                 :            :     using ::com::sun::star::container::XNameAccess;
      69                 :            :     using ::com::sun::star::uno::UNO_QUERY_THROW;
      70                 :            :     using ::com::sun::star::uno::UNO_QUERY;
      71                 :            :     /** === end UNO using === **/
      72                 :            :     namespace MacroExecMode = ::com::sun::star::document::MacroExecMode;
      73                 :            : 
      74                 :            :     //====================================================================
      75                 :            :     //= DocumentMacroMode_Data
      76                 :            :     //====================================================================
      77                 :            :     struct DocumentMacroMode_Data
      78                 :            :     {
      79                 :            :         IMacroDocumentAccess&       m_rDocumentAccess;
      80                 :            :         sal_Bool                    m_bMacroDisabledMessageShown;
      81                 :            :         sal_Bool                    m_bDocMacroDisabledMessageShown;
      82                 :            : 
      83                 :       3407 :         DocumentMacroMode_Data( IMacroDocumentAccess& rDocumentAccess )
      84                 :            :             :m_rDocumentAccess( rDocumentAccess )
      85                 :            :             ,m_bMacroDisabledMessageShown( sal_False )
      86                 :       3407 :             ,m_bDocMacroDisabledMessageShown( sal_False )
      87                 :            :         {
      88                 :       3407 :         }
      89                 :            :     };
      90                 :            : 
      91                 :            :     //====================================================================
      92                 :            :     //= helper
      93                 :            :     //====================================================================
      94                 :            :     namespace
      95                 :            :     {
      96                 :            :         //................................................................
      97                 :          0 :         void lcl_showGeneralSfxErrorOnce( const Reference< XInteractionHandler >& rxHandler, const sal_Int32 nSfxErrorCode, sal_Bool& rbAlreadyShown )
      98                 :            :         {
      99         [ #  # ]:          0 :             if ( rbAlreadyShown )
     100                 :          0 :                 return;
     101                 :            : 
     102         [ #  # ]:          0 :             ErrorCodeRequest aErrorCodeRequest;
     103                 :          0 :             aErrorCodeRequest.ErrCode = nSfxErrorCode;
     104                 :            : 
     105 [ #  # ][ #  # ]:          0 :             SfxMedium::CallApproveHandler( rxHandler, makeAny( aErrorCodeRequest ), sal_False );
     106         [ #  # ]:          0 :             rbAlreadyShown = sal_True;
     107                 :            :         }
     108                 :            : 
     109                 :            :         //................................................................
     110                 :          0 :         void lcl_showMacrosDisabledError( const Reference< XInteractionHandler >& rxHandler, sal_Bool& rbAlreadyShown )
     111                 :            :         {
     112                 :          0 :             lcl_showGeneralSfxErrorOnce( rxHandler, ERRCODE_SFX_MACROS_SUPPORT_DISABLED, rbAlreadyShown );
     113                 :          0 :         }
     114                 :            : 
     115                 :            :         //................................................................
     116                 :          0 :         void lcl_showDocumentMacrosDisabledError( const Reference< XInteractionHandler >& rxHandler, sal_Bool& rbAlreadyShown )
     117                 :            :         {
     118                 :            : #ifdef MACOSX
     119                 :            :             lcl_showGeneralSfxErrorOnce( rxHandler, ERRCODE_SFX_DOCUMENT_MACRO_DISABLED_MAC, rbAlreadyShown );
     120                 :            : #else
     121                 :          0 :             lcl_showGeneralSfxErrorOnce( rxHandler, ERRCODE_SFX_DOCUMENT_MACRO_DISABLED, rbAlreadyShown );
     122                 :            : #endif
     123                 :          0 :         }
     124                 :            : 
     125                 :            :         //................................................................
     126                 :          0 :         sal_Bool lcl_showMacroWarning( const Reference< XInteractionHandler >& rxHandler,
     127                 :            :             const ::rtl::OUString& rDocumentLocation )
     128                 :            :         {
     129         [ #  # ]:          0 :             DocumentMacroConfirmationRequest aRequest;
     130                 :          0 :             aRequest.DocumentURL = rDocumentLocation;
     131 [ #  # ][ #  # ]:          0 :             return SfxMedium::CallApproveHandler( rxHandler, makeAny( aRequest ), sal_True );
                 [ #  # ]
     132                 :            :         }
     133                 :            :     }
     134                 :            : 
     135                 :            :     //====================================================================
     136                 :            :     //= DocumentMacroMode
     137                 :            :     //====================================================================
     138                 :            :     //--------------------------------------------------------------------
     139                 :       3407 :     DocumentMacroMode::DocumentMacroMode( IMacroDocumentAccess& rDocumentAccess )
     140                 :       3407 :         :m_pData( new DocumentMacroMode_Data( rDocumentAccess ) )
     141                 :            :     {
     142                 :       3407 :     }
     143                 :            : 
     144                 :            :     //--------------------------------------------------------------------
     145                 :       3084 :     DocumentMacroMode::~DocumentMacroMode()
     146                 :            :     {
     147                 :       3084 :     }
     148                 :            : 
     149                 :            :     //--------------------------------------------------------------------
     150                 :       2797 :     sal_Bool DocumentMacroMode::allowMacroExecution()
     151                 :            :     {
     152                 :       2797 :         m_pData->m_rDocumentAccess.setCurrentMacroExecMode( MacroExecMode::ALWAYS_EXECUTE_NO_WARN );
     153                 :       2797 :         return sal_True;
     154                 :            :     }
     155                 :            : 
     156                 :            :     //--------------------------------------------------------------------
     157                 :          0 :     sal_Bool DocumentMacroMode::disallowMacroExecution()
     158                 :            :     {
     159                 :          0 :         m_pData->m_rDocumentAccess.setCurrentMacroExecMode( MacroExecMode::NEVER_EXECUTE );
     160                 :          0 :         return sal_False;
     161                 :            :     }
     162                 :            : 
     163                 :            :     //--------------------------------------------------------------------
     164                 :         52 :     sal_Bool DocumentMacroMode::adjustMacroMode( const Reference< XInteractionHandler >& rxInteraction )
     165                 :            :     {
     166                 :         52 :         sal_uInt16 nMacroExecutionMode = m_pData->m_rDocumentAccess.getCurrentMacroExecMode();
     167                 :            : 
     168 [ -  + ][ +  - ]:         52 :         if ( SvtSecurityOptions().IsMacroDisabled() )
     169                 :            :         {
     170                 :            :             // no macro should be executed at all
     171                 :          0 :             lcl_showMacrosDisabledError( rxInteraction, m_pData->m_bMacroDisabledMessageShown );
     172                 :          0 :             return disallowMacroExecution();
     173                 :            :         }
     174                 :            : 
     175                 :            :         // get setting from configuration if required
     176                 :            :         enum AutoConfirmation
     177                 :            :         {
     178                 :            :             eNoAutoConfirm,
     179                 :            :             eAutoConfirmApprove,
     180                 :            :             eAutoConfirmReject
     181                 :            :         };
     182                 :         52 :         AutoConfirmation eAutoConfirm( eNoAutoConfirm );
     183                 :            : 
     184 [ +  - ][ +  - ]:         52 :         if  (   ( nMacroExecutionMode == MacroExecMode::USE_CONFIG )
                 [ -  + ]
     185                 :            :             ||  ( nMacroExecutionMode == MacroExecMode::USE_CONFIG_REJECT_CONFIRMATION )
     186                 :            :             ||  ( nMacroExecutionMode == MacroExecMode::USE_CONFIG_APPROVE_CONFIRMATION )
     187                 :            :             )
     188                 :            :         {
     189         [ #  # ]:          0 :             SvtSecurityOptions aOpt;
     190 [ #  # ][ #  #  :          0 :             switch ( aOpt.GetMacroSecurityLevel() )
                #  #  # ]
     191                 :            :             {
     192                 :            :                 case 3:
     193                 :          0 :                     nMacroExecutionMode = MacroExecMode::FROM_LIST_NO_WARN;
     194                 :          0 :                     break;
     195                 :            :                 case 2:
     196                 :          0 :                     nMacroExecutionMode = MacroExecMode::FROM_LIST_AND_SIGNED_WARN;
     197                 :          0 :                     break;
     198                 :            :                 case 1:
     199                 :          0 :                     nMacroExecutionMode = MacroExecMode::ALWAYS_EXECUTE;
     200                 :          0 :                     break;
     201                 :            :                 case 0:
     202                 :          0 :                     nMacroExecutionMode = MacroExecMode::ALWAYS_EXECUTE_NO_WARN;
     203                 :          0 :                     break;
     204                 :            :                 default:
     205                 :            :                     OSL_FAIL( "DocumentMacroMode::adjustMacroMode: unexpected macro security level!" );
     206                 :          0 :                     nMacroExecutionMode = MacroExecMode::NEVER_EXECUTE;
     207                 :            :             }
     208                 :            : 
     209         [ #  # ]:          0 :             if ( nMacroExecutionMode == MacroExecMode::USE_CONFIG_REJECT_CONFIRMATION )
     210                 :          0 :                 eAutoConfirm = eAutoConfirmReject;
     211         [ #  # ]:          0 :             else if ( nMacroExecutionMode == MacroExecMode::USE_CONFIG_APPROVE_CONFIRMATION )
     212         [ #  # ]:          0 :                 eAutoConfirm = eAutoConfirmApprove;
     213                 :            :         }
     214                 :            : 
     215         [ +  + ]:         52 :         if ( nMacroExecutionMode == MacroExecMode::NEVER_EXECUTE )
     216                 :         13 :             return sal_False;
     217                 :            : 
     218         [ +  - ]:         39 :         if ( nMacroExecutionMode == MacroExecMode::ALWAYS_EXECUTE_NO_WARN )
     219                 :         39 :             return sal_True;
     220                 :            : 
     221                 :            :         try
     222                 :            :         {
     223         [ #  # ]:          0 :             ::rtl::OUString sReferrer( m_pData->m_rDocumentAccess.getDocumentLocation() );
     224                 :            : 
     225                 :            :             // get document location from medium name and check whether it is a trusted one
     226                 :            :             // the service is created ohne document version, since it is not of interest here
     227 [ #  # ][ #  # ]:          0 :             ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
     228                 :          0 :             Reference< XDocumentDigitalSignatures > xSignatures;
     229 [ #  # ][ #  # ]:          0 :             if ( aContext.createComponent( "com.sun.star.security.DocumentDigitalSignatures", xSignatures ) )
     230                 :            :             {
     231         [ #  # ]:          0 :                 INetURLObject aURLReferer( sReferrer );
     232                 :            : 
     233                 :          0 :                 ::rtl::OUString aLocation;
     234 [ #  # ][ #  # ]:          0 :                 if ( aURLReferer.removeSegment() )
     235         [ #  # ]:          0 :                     aLocation = aURLReferer.GetMainURL( INetURLObject::NO_DECODE );
     236                 :            : 
     237 [ #  # ][ #  # ]:          0 :                 if ( !aLocation.isEmpty() && xSignatures->isLocationTrusted( aLocation ) )
         [ #  # ][ #  # ]
                 [ #  # ]
     238                 :            :                 {
     239         [ #  # ]:          0 :                     return allowMacroExecution();
     240 [ #  # ][ #  # ]:          0 :                 }
                 [ #  # ]
     241                 :            :             }
     242                 :            : 
     243                 :            :             // at this point it is clear that the document is not in the secure location
     244         [ #  # ]:          0 :             if ( nMacroExecutionMode == MacroExecMode::FROM_LIST_NO_WARN )
     245                 :            :             {
     246         [ #  # ]:          0 :                 lcl_showDocumentMacrosDisabledError( rxInteraction, m_pData->m_bDocMacroDisabledMessageShown );
     247         [ #  # ]:          0 :                 return disallowMacroExecution();
     248                 :            :             }
     249                 :            : 
     250                 :            :             // check whether the document is signed with trusted certificate
     251         [ #  # ]:          0 :             if ( nMacroExecutionMode != MacroExecMode::FROM_LIST )
     252                 :            :             {
     253                 :            :                 // the trusted macro check will also retrieve the signature state ( small optimization )
     254         [ #  # ]:          0 :                 sal_Bool bHasTrustedMacroSignature = m_pData->m_rDocumentAccess.hasTrustedScriptingSignature( nMacroExecutionMode != MacroExecMode::FROM_LIST_AND_SIGNED_NO_WARN );
     255                 :            : 
     256         [ #  # ]:          0 :                 sal_uInt16 nSignatureState = m_pData->m_rDocumentAccess.getScriptingSignatureState();
     257         [ #  # ]:          0 :                 if ( nSignatureState == SIGNATURESTATE_SIGNATURES_BROKEN )
     258                 :            :                 {
     259                 :            :                     // the signature is broken, no macro execution
     260         [ #  # ]:          0 :                     if ( nMacroExecutionMode != MacroExecMode::FROM_LIST_AND_SIGNED_NO_WARN )
     261         [ #  # ]:          0 :                         m_pData->m_rDocumentAccess.showBrokenSignatureWarning( rxInteraction );
     262                 :            : 
     263         [ #  # ]:          0 :                     return disallowMacroExecution();
     264                 :            :                 }
     265         [ #  # ]:          0 :                 else if ( bHasTrustedMacroSignature )
     266                 :            :                 {
     267                 :            :                     // there is trusted macro signature, allow macro execution
     268         [ #  # ]:          0 :                     return allowMacroExecution();
     269                 :            :                 }
     270 [ #  # ][ #  # ]:          0 :                 else if ( nSignatureState == SIGNATURESTATE_SIGNATURES_OK
     271                 :            :                        || nSignatureState == SIGNATURESTATE_SIGNATURES_NOTVALIDATED )
     272                 :            :                 {
     273                 :            :                     // there is valid signature, but it is not from the trusted author
     274         [ #  # ]:          0 :                     return disallowMacroExecution();
     275                 :            :                 }
     276                 :            :             }
     277                 :            : 
     278                 :            :             // at this point it is clear that the document is neither in secure location nor signed with trusted certificate
     279 [ #  # ][ #  # ]:          0 :             if  (   ( nMacroExecutionMode == MacroExecMode::FROM_LIST_AND_SIGNED_NO_WARN )
     280                 :            :                 ||  ( nMacroExecutionMode == MacroExecMode::FROM_LIST_AND_SIGNED_WARN )
     281                 :            :                 )
     282                 :            :             {
     283         [ #  # ]:          0 :                 if  ( nMacroExecutionMode == MacroExecMode::FROM_LIST_AND_SIGNED_WARN )
     284         [ #  # ]:          0 :                     lcl_showDocumentMacrosDisabledError( rxInteraction, m_pData->m_bDocMacroDisabledMessageShown );
     285                 :            : 
     286         [ #  # ]:          0 :                 return disallowMacroExecution();
     287 [ #  # ][ #  # ]:          0 :             }
         [ #  # ][ #  # ]
     288                 :            :         }
     289   [ #  #  #  # ]:          0 :         catch ( const Exception& )
     290                 :            :         {
     291   [ #  #  #  #  :          0 :             if  (   ( nMacroExecutionMode == MacroExecMode::FROM_LIST_NO_WARN )
                   #  # ]
     292                 :            :                 ||  ( nMacroExecutionMode == MacroExecMode::FROM_LIST_AND_SIGNED_WARN )
     293                 :            :                 ||  ( nMacroExecutionMode == MacroExecMode::FROM_LIST_AND_SIGNED_NO_WARN )
     294                 :            :                 )
     295                 :            :             {
     296         [ #  # ]:          0 :                 return disallowMacroExecution();
     297                 :            :             }
     298                 :            :         }
     299                 :            : 
     300                 :            :         // conformation is required
     301                 :          0 :         sal_Bool bSecure = sal_False;
     302                 :            : 
     303         [ #  # ]:          0 :         if ( eAutoConfirm == eNoAutoConfirm )
     304                 :            :         {
     305         [ #  # ]:          0 :             ::rtl::OUString sReferrer( m_pData->m_rDocumentAccess.getDocumentLocation() );
     306                 :            : 
     307                 :          0 :             ::rtl::OUString aSystemFileURL;
     308 [ #  # ][ #  # ]:          0 :             if ( osl::FileBase::getSystemPathFromFileURL( sReferrer, aSystemFileURL ) == osl::FileBase::E_None )
     309                 :          0 :                 sReferrer = aSystemFileURL;
     310                 :            : 
     311         [ #  # ]:          0 :             bSecure = lcl_showMacroWarning( rxInteraction, sReferrer );
     312                 :            :         }
     313                 :            :         else
     314                 :          0 :             bSecure = ( eAutoConfirm == eAutoConfirmApprove );
     315                 :            : 
     316         [ #  # ]:         52 :         return ( bSecure ? allowMacroExecution() : disallowMacroExecution() );
     317                 :            :     }
     318                 :            : 
     319                 :            :     //--------------------------------------------------------------------
     320                 :       2565 :     sal_Bool DocumentMacroMode::isMacroExecutionDisallowed() const
     321                 :            :     {
     322                 :       2565 :         return m_pData->m_rDocumentAccess.getCurrentMacroExecMode() == MacroExecMode::NEVER_EXECUTE;
     323                 :            :     }
     324                 :            : 
     325                 :            :     //--------------------------------------------------------------------
     326                 :       2582 :     sal_Bool DocumentMacroMode::hasMacroLibrary() const
     327                 :            :     {
     328                 :       2582 :         sal_Bool bHasMacroLib = sal_False;
     329                 :            : #ifndef DISABLE_SCRIPTING
     330                 :            :         try
     331                 :            :         {
     332         [ +  - ]:       2582 :             Reference< XEmbeddedScripts > xScripts( m_pData->m_rDocumentAccess.getEmbeddedDocumentScripts() );
     333                 :       2582 :             Reference< XLibraryContainer > xContainer;
     334         [ +  - ]:       2582 :             if ( xScripts.is() )
     335 [ +  - ][ +  + ]:       2582 :                 xContainer.set( xScripts->getBasicLibraries(), UNO_QUERY_THROW );
                 [ +  - ]
     336                 :            : 
     337         [ +  - ]:       1379 :             Reference< XVBACompatibility > xDocVBAMode( xContainer, UNO_QUERY );
     338 [ +  - ][ +  - ]:       1379 :             sal_Bool bIsVBAMode = ( xDocVBAMode.is() && xDocVBAMode->getVBACompatibilityMode() );
         [ +  - ][ +  + ]
     339         [ +  - ]:       1379 :             if ( xContainer.is() )
     340                 :            :             {
     341                 :            :                 // a library container exists; check if it's empty
     342                 :            : 
     343                 :            :                 // if there are libraries except the "Standard" library
     344                 :            :                 // we assume that they are not empty (because they have been created by the user)
     345 [ +  - ][ +  - ]:       1379 :                 if ( !xContainer->hasElements() )
                 [ +  + ]
     346                 :       1316 :                     bHasMacroLib = sal_False;
     347                 :            :                 else
     348                 :            :                 {
     349         [ +  - ]:         63 :                     ::rtl::OUString aStdLibName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
     350 [ +  - ][ +  - ]:         63 :                     Sequence< ::rtl::OUString > aElements = xContainer->getElementNames();
     351                 :         63 :                     sal_Int32 nElementCount = aElements.getLength();
     352         [ +  - ]:         63 :                     if ( nElementCount )
     353                 :            :                     {
     354                 :            :                         // old check, if more than 1 library or the first library isn't the expected 'Standard'
     355                 :            :                         // trigger the security 'nag' dialog
     356 [ +  + ][ +  - ]:         63 :                         if ( !bIsVBAMode && ( nElementCount > 1 || !aElements[0].equals( aStdLibName ) ) )
         [ +  - ][ -  + ]
                 [ -  + ]
     357                 :          0 :                             bHasMacroLib = sal_True;
     358                 :            :                         else
     359                 :            :                         {
     360                 :            :                             // other wise just check all libraries for executeable code
     361         [ +  - ]:         63 :                             Reference< XLibraryQueryExecutable > xLib( xContainer, UNO_QUERY );
     362         [ +  - ]:         63 :                             if ( xLib.is() )
     363                 :            :                             {
     364                 :         63 :                                 const ::rtl::OUString* pElementName = aElements.getConstArray();
     365         [ +  + ]:        126 :                                 for ( sal_Int32 index = 0; index < nElementCount; ++index )
     366                 :            :                                 {
     367 [ +  - ][ +  - ]:         63 :                                     bHasMacroLib = xLib->HasExecutableCode( pElementName[index] );
     368         [ +  + ]:         63 :                                     if ( bHasMacroLib )
     369                 :         17 :                                         break;
     370                 :            :                                 }
     371                 :         63 :                             }
     372                 :            :                         }
     373         [ +  - ]:         63 :                     }
     374                 :            :                 }
     375                 :            :             }
     376 [ +  + ][ -  + ]:       1379 :             if ( bIsVBAMode && !bHasMacroLib && xScripts.is() )
         [ #  # ][ -  + ]
     377                 :            :             {
     378 [ #  # ][ #  # ]:          0 :                 Reference< XLibraryContainer > xDlgContainer( xScripts->getDialogLibraries(), UNO_QUERY );
                 [ #  # ]
     379 [ #  # ][ #  # ]:          0 :                 if ( xDlgContainer.is() && xDlgContainer->hasElements() )
         [ #  # ][ #  # ]
                 [ #  # ]
     380                 :            :                 {
     381 [ #  # ][ #  # ]:          0 :                     Sequence< ::rtl::OUString > aElements = xDlgContainer->getElementNames();
     382                 :          0 :                     sal_Int32 nElementCount = aElements.getLength();
     383                 :          0 :                     const ::rtl::OUString* pElementName = aElements.getConstArray();
     384         [ #  # ]:          0 :                     for ( sal_Int32 index = 0; index < nElementCount; ++index )
     385                 :            :                     {
     386                 :          0 :                         Reference< XNameAccess > xNameAccess;
     387 [ #  # ][ #  # ]:          0 :                         xDlgContainer->getByName( pElementName[index] ) >>= xNameAccess;
                 [ #  # ]
     388 [ #  # ][ #  # ]:          0 :                         if ( xNameAccess.is() && xNameAccess->hasElements() )
         [ #  # ][ #  # ]
                 [ #  # ]
     389                 :            :                         {
     390                 :          0 :                             bHasMacroLib = sal_True;
     391                 :            :                             break;
     392                 :            :                         }
     393 [ #  # ][ #  # ]:          0 :                     }
     394                 :          0 :                 }
     395         [ -  + ]:       2582 :             }
     396                 :            :         }
     397                 :       1203 :         catch( const Exception& )
     398                 :            :         {
     399                 :            :             DBG_UNHANDLED_EXCEPTION();
     400                 :            :         }
     401                 :            : #endif
     402                 :       2582 :         return bHasMacroLib;
     403                 :            :     }
     404                 :            : 
     405                 :            :     //--------------------------------------------------------------------
     406                 :       2612 :     sal_Bool DocumentMacroMode::storageHasMacros( const Reference< XStorage >& rxStorage )
     407                 :            :     {
     408                 :       2612 :         sal_Bool bHasMacros = sal_False;
     409         [ +  + ]:       2612 :         if ( rxStorage.is() )
     410                 :            :         {
     411                 :            :             try
     412                 :            :             {
     413         [ +  - ]:       2231 :                 const ::rtl::OUString s_sBasicStorageName( ::rtl::OUString::intern( RTL_CONSTASCII_USTRINGPARAM( "Basic" ) ) );
     414         [ +  - ]:       2231 :                 const ::rtl::OUString s_sScriptsStorageName( ::rtl::OUString::intern( RTL_CONSTASCII_USTRINGPARAM( "Scripts" ) ) );
     415                 :            : 
     416 [ +  - ][ +  - ]:       2231 :                 bHasMacros =(   (   rxStorage->hasByName( s_sBasicStorageName )
     417 [ +  - ][ +  - ]:         16 :                                 &&  rxStorage->isStorageElement( s_sBasicStorageName )
     418                 :            :                                 )
     419 [ +  - ][ +  - ]:       2215 :                             ||  (   rxStorage->hasByName( s_sScriptsStorageName )
     420 [ #  # ][ #  # ]:          0 :                                 &&  rxStorage->isStorageElement( s_sScriptsStorageName )
     421                 :            :                                 )
     422 [ +  + ][ -  + ]:       4462 :                             );
         [ -  + ][ #  # ]
                 [ #  # ]
     423                 :            :             }
     424                 :          0 :             catch ( const Exception& )
     425                 :            :             {
     426                 :            :                 DBG_UNHANDLED_EXCEPTION();
     427                 :            :             }
     428                 :            :         }
     429                 :       2612 :         return bHasMacros;
     430                 :            :     }
     431                 :            : 
     432                 :            :     //--------------------------------------------------------------------
     433                 :       2598 :     sal_Bool DocumentMacroMode::checkMacrosOnLoading( const Reference< XInteractionHandler >& rxInteraction )
     434                 :            :     {
     435                 :       2598 :         sal_Bool bAllow = sal_False;
     436 [ +  - ][ -  + ]:       2598 :         if ( SvtSecurityOptions().IsMacroDisabled() )
     437                 :            :         {
     438                 :            :             // no macro should be executed at all
     439                 :          0 :             bAllow = disallowMacroExecution();
     440                 :            :         }
     441                 :            :         else
     442                 :            :         {
     443 [ +  + ][ +  + ]:       2598 :             if ( m_pData->m_rDocumentAccess.documentStorageHasMacros() || hasMacroLibrary() )
                 [ +  + ]
     444                 :            :             {
     445                 :         33 :                 bAllow = adjustMacroMode( rxInteraction );
     446                 :            :             }
     447         [ +  + ]:       2565 :             else if ( !isMacroExecutionDisallowed() )
     448                 :            :             {
     449                 :            :                 // if macros will be added by the user later, the security check is obsolete
     450                 :       1122 :                 bAllow = allowMacroExecution();
     451                 :            :             }
     452                 :            :         }
     453                 :       2598 :         return bAllow;
     454                 :            :     }
     455                 :            : 
     456                 :            : //........................................................................
     457                 :            : } // namespace sfx2
     458                 :            : //........................................................................
     459                 :            : 
     460                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10