LCOV - code coverage report
Current view: top level - libreoffice/unotools/source/config - securityoptions.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 118 484 24.4 %
Date: 2012-12-27 Functions: 15 54 27.8 %
Legend: Lines: hit not hit

          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 <unotools/securityoptions.hxx>
      22             : #include <unotools/configmgr.hxx>
      23             : #include <unotools/configitem.hxx>
      24             : #include <tools/debug.hxx>
      25             : #include <com/sun/star/uno/Any.hxx>
      26             : #include <com/sun/star/uno/Sequence.hxx>
      27             : 
      28             : #include <com/sun/star/beans/PropertyValue.hpp>
      29             : #include <comphelper/sequenceasvector.hxx>
      30             : #include <tools/urlobj.hxx>
      31             : #include <tools/wldcrd.hxx>
      32             : 
      33             : #include <unotools/pathoptions.hxx>
      34             : 
      35             : #include <rtl/logfile.hxx>
      36             : #include "itemholder1.hxx"
      37             : 
      38             : //_________________________________________________________________________________________________________________
      39             : //  namespaces
      40             : //_________________________________________________________________________________________________________________
      41             : 
      42             : using namespace ::utl                   ;
      43             : using namespace ::rtl                   ;
      44             : using namespace ::osl                   ;
      45             : using namespace ::com::sun::star::uno   ;
      46             : 
      47             : #define ROOTNODE_SECURITY               OUString(RTL_CONSTASCII_USTRINGPARAM("Office.Common/Security/Scripting"))
      48             : #define DEFAULT_SECUREURL               Sequence< OUString >()
      49             : #define DEFAULT_TRUSTEDAUTHORS          Sequence< SvtSecurityOptions::Certificate >()
      50             : 
      51             : // xmlsec05 depricated
      52             : #define DEFAULT_STAROFFICEBASIC         eALWAYS_EXECUTE
      53             : 
      54             : #define CSTR_SECUREURL                  "SecureURL"
      55             : #define CSTR_DOCWARN_SAVEORSEND         "WarnSaveOrSendDoc"
      56             : #define CSTR_DOCWARN_SIGNING            "WarnSignDoc"
      57             : #define CSTR_DOCWARN_PRINT              "WarnPrintDoc"
      58             : #define CSTR_DOCWARN_CREATEPDF          "WarnCreatePDF"
      59             : #define CSTR_DOCWARN_REMOVEPERSONALINFO "RemovePersonalInfoOnSaving"
      60             : #define CSTR_DOCWARN_RECOMMENDPASSWORD  "RecommendPasswordProtection"
      61             : #define CSTR_CTRLCLICK_HYPERLINK        "HyperlinksWithCtrlClick"
      62             : #define CSTR_MACRO_SECLEVEL             "MacroSecurityLevel"
      63             : #define CSTR_MACRO_TRUSTEDAUTHORS       "TrustedAuthors"
      64             : #define CSTR_MACRO_DISABLE              "DisableMacrosExecution"
      65             : #define CSTR_TRUSTEDAUTHOR_SUBJECTNAME  "SubjectName"
      66             : #define CSTR_TRUSTEDAUTHOR_SERIALNUMBER "SerialNumber"
      67             : #define CSTR_TRUSTEDAUTHOR_RAWDATA      "RawData"
      68             : 
      69             : #define PROPERTYNAME_SECUREURL                  OUString(RTL_CONSTASCII_USTRINGPARAM(CSTR_SECUREURL                     ))
      70             : #define PROPERTYNAME_DOCWARN_SAVEORSEND         OUString(RTL_CONSTASCII_USTRINGPARAM(CSTR_DOCWARN_SAVEORSEND            ))
      71             : #define PROPERTYNAME_DOCWARN_SIGNING            OUString(RTL_CONSTASCII_USTRINGPARAM(CSTR_DOCWARN_SIGNING               ))
      72             : #define PROPERTYNAME_DOCWARN_PRINT              OUString(RTL_CONSTASCII_USTRINGPARAM(CSTR_DOCWARN_PRINT                 ))
      73             : #define PROPERTYNAME_DOCWARN_CREATEPDF          OUString(RTL_CONSTASCII_USTRINGPARAM(CSTR_DOCWARN_CREATEPDF             ))
      74             : #define PROPERTYNAME_DOCWARN_REMOVEPERSONALINFO OUString(RTL_CONSTASCII_USTRINGPARAM(CSTR_DOCWARN_REMOVEPERSONALINFO    ))
      75             : #define PROPERTYNAME_DOCWARN_RECOMMENDPASSWORD  OUString(RTL_CONSTASCII_USTRINGPARAM(CSTR_DOCWARN_RECOMMENDPASSWORD     ))
      76             : #define PROPERTYNAME_CTRLCLICK_HYPERLINK        OUString(RTL_CONSTASCII_USTRINGPARAM(CSTR_CTRLCLICK_HYPERLINK           ))
      77             : #define PROPERTYNAME_MACRO_SECLEVEL             OUString(RTL_CONSTASCII_USTRINGPARAM(CSTR_MACRO_SECLEVEL                ))
      78             : #define PROPERTYNAME_MACRO_TRUSTEDAUTHORS       OUString(RTL_CONSTASCII_USTRINGPARAM(CSTR_MACRO_TRUSTEDAUTHORS          ))
      79             : #define PROPERTYNAME_MACRO_DISABLE              OUString(RTL_CONSTASCII_USTRINGPARAM(CSTR_MACRO_DISABLE                 ))
      80             : #define PROPERTYNAME_TRUSTEDAUTHOR_SUBJECTNAME  OUString(RTL_CONSTASCII_USTRINGPARAM(CSTR_TRUSTEDAUTHOR_SUBJECTNAME))
      81             : #define PROPERTYNAME_TRUSTEDAUTHOR_SERIALNUMBER OUString(RTL_CONSTASCII_USTRINGPARAM(CSTR_TRUSTEDAUTHOR_SERIALNUMBER))
      82             : #define PROPERTYNAME_TRUSTEDAUTHOR_RAWDATA      OUString(RTL_CONSTASCII_USTRINGPARAM(CSTR_TRUSTEDAUTHOR_RAWDATA))
      83             : 
      84             : // xmlsec05 depricated
      85             : #define PROPERTYNAME_STAROFFICEBASIC    OUString(RTL_CONSTASCII_USTRINGPARAM("OfficeBasic"  ))
      86             : #define PROPERTYNAME_EXECUTEPLUGINS     OUString(RTL_CONSTASCII_USTRINGPARAM("ExecutePlugins"  ))
      87             : #define PROPERTYNAME_WARNINGENABLED     OUString(RTL_CONSTASCII_USTRINGPARAM("Warning"  ))
      88             : #define PROPERTYNAME_CONFIRMATIONENABLED OUString(RTL_CONSTASCII_USTRINGPARAM("Confirmation"  ))
      89             : // xmlsec05 depricated
      90             : 
      91             : 
      92             : #define PROPERTYHANDLE_SECUREURL                    0
      93             : 
      94             : // xmlsec05 depricated
      95             : #define PROPERTYHANDLE_STAROFFICEBASIC  1
      96             : #define PROPERTYHANDLE_EXECUTEPLUGINS   2
      97             : #define PROPERTYHANDLE_WARNINGENABLED   3
      98             : #define PROPERTYHANDLE_CONFIRMATIONENABLED 4
      99             : // xmlsec05 depricated
     100             : 
     101             : #define PROPERTYHANDLE_DOCWARN_SAVEORSEND           5
     102             : #define PROPERTYHANDLE_DOCWARN_SIGNING              6
     103             : #define PROPERTYHANDLE_DOCWARN_PRINT                7
     104             : #define PROPERTYHANDLE_DOCWARN_CREATEPDF            8
     105             : #define PROPERTYHANDLE_DOCWARN_REMOVEPERSONALINFO   9
     106             : #define PROPERTYHANDLE_DOCWARN_RECOMMENDPASSWORD    10
     107             : #define PROPERTYHANDLE_CTRLCLICK_HYPERLINK          11
     108             : #define PROPERTYHANDLE_MACRO_SECLEVEL               12
     109             : #define PROPERTYHANDLE_MACRO_TRUSTEDAUTHORS         13
     110             : #define PROPERTYHANDLE_MACRO_DISABLE                14
     111             : 
     112             : #define PROPERTYCOUNT                               15
     113             : #define PROPERTYHANDLE_INVALID                      -1
     114             : 
     115             : #define CFG_READONLY_DEFAULT                        sal_False
     116             : 
     117             : //_________________________________________________________________________________________________________________
     118             : //  private declarations!
     119             : //_________________________________________________________________________________________________________________
     120             : 
     121             : class SvtSecurityOptions_Impl : public ConfigItem
     122             : {
     123             :     //-------------------------------------------------------------------------------------------------------------
     124             :     //  public methods
     125             :     //-------------------------------------------------------------------------------------------------------------
     126             : 
     127             :     public:
     128             : 
     129             :         //---------------------------------------------------------------------------------------------------------
     130             :         //  constructor / destructor
     131             :         //---------------------------------------------------------------------------------------------------------
     132             : 
     133             :          SvtSecurityOptions_Impl();
     134             :         ~SvtSecurityOptions_Impl();
     135             : 
     136             :         //---------------------------------------------------------------------------------------------------------
     137             :         //  overloaded methods of baseclass
     138             :         //---------------------------------------------------------------------------------------------------------
     139             : 
     140             :         /*-****************************************************************************************************//**
     141             :             @short      called for notify of configmanager
     142             :             @descr      These method is called from the ConfigManager before application ends or from the
     143             :                          PropertyChangeListener if the sub tree broadcasts changes. You must update your
     144             :                         internal values.
     145             : 
     146             :             @seealso    baseclass ConfigItem
     147             : 
     148             :             @param      "seqPropertyNames" is the list of properties which should be updated.
     149             :             @return     -
     150             : 
     151             :             @onerror    -
     152             :         *//*-*****************************************************************************************************/
     153             : 
     154             :         virtual void Notify( const Sequence< OUString >& seqPropertyNames );
     155             : 
     156             :         /*-****************************************************************************************************//**
     157             :             @short      write changes to configuration
     158             :             @descr      These method writes the changed values into the sub tree
     159             :                         and should always called in our destructor to guarantee consistency of config data.
     160             : 
     161             :             @seealso    baseclass ConfigItem
     162             : 
     163             :             @param      -
     164             :             @return     -
     165             : 
     166             :             @onerror    -
     167             :         *//*-*****************************************************************************************************/
     168             : 
     169             :         virtual void Commit();
     170             : 
     171             :         //---------------------------------------------------------------------------------------------------------
     172             :         //  public interface
     173             :         //---------------------------------------------------------------------------------------------------------
     174             : 
     175             :         sal_Bool                IsReadOnly      ( SvtSecurityOptions::EOption eOption                   ) const ;
     176             : 
     177             :         Sequence< OUString >    GetSecureURLs   (                                                       ) const ;
     178             :         void                    SetSecureURLs   (   const   Sequence< OUString >&   seqURLList          )       ;
     179             :         sal_Bool                IsSecureURL     (   const   OUString&               sURL,
     180             :                                                     const   OUString&               sReferer            ) const ;
     181             :         inline sal_Int32        GetMacroSecurityLevel   (                                               ) const ;
     182             :         void                    SetMacroSecurityLevel   ( sal_Int32 _nLevel                             )       ;
     183             : 
     184             :         inline sal_Bool         IsMacroDisabled         (                                               ) const ;
     185             : 
     186             :         Sequence< SvtSecurityOptions::Certificate > GetTrustedAuthors       (                                                                                       ) const ;
     187             :         void                                        SetTrustedAuthors       ( const Sequence< SvtSecurityOptions::Certificate >& rAuthors                           )       ;
     188             : 
     189             :         sal_Bool                IsOptionSet     ( SvtSecurityOptions::EOption eOption                   ) const ;
     190             :         sal_Bool                SetOption       ( SvtSecurityOptions::EOption eOption, sal_Bool bValue  )       ;
     191             :         sal_Bool                IsOptionEnabled ( SvtSecurityOptions::EOption eOption                   ) const ;
     192             : private:
     193             : 
     194             :         /*-****************************************************************************************************//**
     195             :             @short      return list of key names of ouer configuration management which represent our module tree
     196             :             @descr      These methods return a static const list of key names. We need it to get needed values from our
     197             :                         configuration management.
     198             : 
     199             :             @seealso    -
     200             : 
     201             :             @param      -
     202             :             @return     A list of needed configuration keys is returned.
     203             : 
     204             :             @onerror    -
     205             :         *//*-*****************************************************************************************************/
     206             : 
     207             :         void                    SetProperty( sal_Int32 nHandle, const Any& rValue, sal_Bool bReadOnly );
     208             :         void                    LoadAuthors( void );
     209             :         static sal_Int32        GetHandle( const OUString& rPropertyName );
     210             :         bool                    GetOption( SvtSecurityOptions::EOption eOption, sal_Bool*& rpValue, sal_Bool*& rpRO );
     211             : 
     212             :         static Sequence< OUString > GetPropertyNames();
     213             : 
     214             :         Sequence< OUString >                        m_seqSecureURLs;
     215             :         sal_Bool                                    m_bSaveOrSend;
     216             :         sal_Bool                                    m_bSigning;
     217             :         sal_Bool                                    m_bPrint;
     218             :         sal_Bool                                    m_bCreatePDF;
     219             :         sal_Bool                                    m_bRemoveInfo;
     220             :         sal_Bool                                    m_bRecommendPwd;
     221             :         sal_Bool                                    m_bCtrlClickHyperlink;
     222             :         sal_Int32                                   m_nSecLevel;
     223             :         Sequence< SvtSecurityOptions::Certificate > m_seqTrustedAuthors;
     224             :         sal_Bool                                    m_bDisableMacros;
     225             : 
     226             :         sal_Bool                                    m_bROSecureURLs;
     227             :         sal_Bool                                    m_bROSaveOrSend;
     228             :         sal_Bool                                    m_bROSigning;
     229             :         sal_Bool                                    m_bROPrint;
     230             :         sal_Bool                                    m_bROCreatePDF;
     231             :         sal_Bool                                    m_bRORemoveInfo;
     232             :         sal_Bool                                    m_bRORecommendPwd;
     233             :         sal_Bool                                    m_bROCtrlClickHyperlink;
     234             :         sal_Bool                                    m_bROSecLevel;
     235             :         sal_Bool                                    m_bROTrustedAuthors;
     236             :         sal_Bool                                    m_bRODisableMacros;
     237             : 
     238             : 
     239             :         // xmlsec05 depricated
     240             :         EBasicSecurityMode      m_eBasicMode;
     241             :         sal_Bool                m_bExecutePlugins;
     242             :         sal_Bool                m_bWarning;
     243             :         sal_Bool                m_bConfirmation;
     244             : 
     245             :         sal_Bool                m_bROConfirmation;
     246             :         sal_Bool                m_bROWarning;
     247             :         sal_Bool                m_bROExecutePlugins;
     248             :         sal_Bool                m_bROBasicMode;
     249             :         public:
     250             :         sal_Bool IsWarningEnabled() const;
     251             :         void SetWarningEnabled( sal_Bool bSet );
     252             :         sal_Bool IsConfirmationEnabled() const;
     253             :         void SetConfirmationEnabled( sal_Bool bSet );
     254             :         sal_Bool    IsExecutePlugins() const;
     255             :         void        SetExecutePlugins( sal_Bool bSet );
     256             :         EBasicSecurityMode      GetBasicMode    (                                               ) const ;
     257             :         void                    SetBasicMode    (           EBasicSecurityMode      eMode       )       ;
     258             : };
     259             : 
     260             : //*****************************************************************************************************************
     261             : //  constructor
     262             : //*****************************************************************************************************************
     263          15 : SvtSecurityOptions_Impl::SvtSecurityOptions_Impl()
     264             :     :ConfigItem             ( ROOTNODE_SECURITY         )
     265             :     ,m_seqSecureURLs        ( DEFAULT_SECUREURL         )
     266             :     ,m_bSaveOrSend          ( sal_True                  )
     267             :     ,m_bSigning             ( sal_True                  )
     268             :     ,m_bPrint               ( sal_True                  )
     269             :     ,m_bCreatePDF           ( sal_True                  )
     270             :     ,m_bRemoveInfo          ( sal_True                  )
     271             :     ,m_nSecLevel            ( sal_True                  )
     272             :     ,m_seqTrustedAuthors    ( DEFAULT_TRUSTEDAUTHORS    )
     273             :     ,m_bDisableMacros       ( sal_False                 )
     274             :     ,m_bROSecureURLs        ( CFG_READONLY_DEFAULT      )
     275             :     ,m_bROSaveOrSend        ( CFG_READONLY_DEFAULT      )
     276             :     ,m_bROSigning           ( CFG_READONLY_DEFAULT      )
     277             :     ,m_bROPrint             ( CFG_READONLY_DEFAULT      )
     278             :     ,m_bROCreatePDF         ( CFG_READONLY_DEFAULT      )
     279             :     ,m_bRORemoveInfo        ( CFG_READONLY_DEFAULT      )
     280             :     ,m_bROSecLevel          ( CFG_READONLY_DEFAULT      )
     281             :     ,m_bROTrustedAuthors    ( CFG_READONLY_DEFAULT      )
     282             :     ,m_bRODisableMacros     ( sal_True                  ) // currently is not intended to be changed
     283             : 
     284             :     // xmlsec05 depricated
     285             :     ,   m_eBasicMode        ( DEFAULT_STAROFFICEBASIC )
     286             :     ,   m_bExecutePlugins   ( sal_True                )
     287             :     ,   m_bWarning          ( sal_True                )
     288             :     ,   m_bConfirmation     ( sal_True                )
     289             :     ,   m_bROConfirmation   ( CFG_READONLY_DEFAULT    )
     290             :     ,   m_bROWarning        ( CFG_READONLY_DEFAULT    )
     291             :     ,   m_bROExecutePlugins ( CFG_READONLY_DEFAULT    )
     292          15 :     ,   m_bROBasicMode      ( CFG_READONLY_DEFAULT    )
     293             :     // xmlsec05 depricated
     294             : 
     295             : {
     296          15 :     Sequence< OUString >    seqNames    = GetPropertyNames  (           );
     297          15 :     Sequence< Any >         seqValues   = GetProperties     ( seqNames  );
     298          15 :     Sequence< sal_Bool >    seqRO       = GetReadOnlyStates ( seqNames  );
     299             : 
     300             :     // Safe impossible cases.
     301             :     // We need values from ALL configuration keys.
     302             :     // Follow assignment use order of values in relation to our list of key names!
     303             :     DBG_ASSERT( !(seqNames.getLength()!=seqValues.getLength()), "SvtSecurityOptions_Impl::SvtSecurityOptions_Impl()\nI miss some values of configuration keys!\n" );
     304             : 
     305             :     // Copy values from list in right order to our internal member.
     306          15 :     sal_Int32               nPropertyCount = seqValues.getLength();
     307         240 :     for( sal_Int32 nProperty = 0 ; nProperty < nPropertyCount ; ++nProperty )
     308         225 :         SetProperty( nProperty, seqValues[ nProperty ], seqRO[ nProperty ] );
     309             : 
     310          15 :     LoadAuthors();
     311             : 
     312             :     // Enable notification mechanism of our baseclass.
     313             :     // We need it to get information about changes outside these class on our used configuration keys!*/
     314             : 
     315          15 :     EnableNotification( seqNames );
     316          15 : }
     317             : 
     318             : //*****************************************************************************************************************
     319             : //  destructor
     320             : //*****************************************************************************************************************
     321          45 : SvtSecurityOptions_Impl::~SvtSecurityOptions_Impl()
     322             : {
     323          15 :     if( IsModified() )
     324           0 :         Commit();
     325          30 : }
     326             : 
     327         225 : void SvtSecurityOptions_Impl::SetProperty( sal_Int32 nProperty, const Any& rValue, sal_Bool bRO )
     328             : {
     329         225 :     switch( nProperty )
     330             :     {
     331             :         case PROPERTYHANDLE_SECUREURL:
     332             :         {
     333          15 :             m_seqSecureURLs.realloc( 0 );
     334          15 :             rValue >>= m_seqSecureURLs;
     335          15 :             SvtPathOptions  aOpt;
     336          15 :             sal_uInt32      nCount = m_seqSecureURLs.getLength();
     337          15 :             for( sal_uInt32 nItem = 0 ; nItem < nCount ; ++nItem )
     338           0 :                 m_seqSecureURLs[ nItem ] = aOpt.SubstituteVariable( m_seqSecureURLs[ nItem ] );
     339          15 :             m_bROSecureURLs = bRO;
     340             :         }
     341          15 :         break;
     342             : 
     343             :         case PROPERTYHANDLE_DOCWARN_SAVEORSEND:
     344             :         {
     345          15 :             rValue >>= m_bSaveOrSend;
     346          15 :             m_bROSaveOrSend = bRO;
     347             :         }
     348          15 :         break;
     349             : 
     350             :         case PROPERTYHANDLE_DOCWARN_SIGNING:
     351             :         {
     352          15 :             rValue >>= m_bSigning;
     353          15 :             m_bROSigning = bRO;
     354             :         }
     355          15 :         break;
     356             : 
     357             :         case PROPERTYHANDLE_DOCWARN_PRINT:
     358             :         {
     359          15 :             rValue >>= m_bPrint;
     360          15 :             m_bROPrint = bRO;
     361             :         }
     362          15 :         break;
     363             : 
     364             :         case PROPERTYHANDLE_DOCWARN_CREATEPDF:
     365             :         {
     366          15 :             rValue >>= m_bCreatePDF;
     367          15 :             m_bROCreatePDF = bRO;
     368             :         }
     369          15 :         break;
     370             : 
     371             :         case PROPERTYHANDLE_DOCWARN_REMOVEPERSONALINFO:
     372             :         {
     373          15 :             rValue >>= m_bRemoveInfo;
     374          15 :             m_bRORemoveInfo = bRO;
     375             :         }
     376          15 :         break;
     377             : 
     378             :         case PROPERTYHANDLE_DOCWARN_RECOMMENDPASSWORD:
     379             :         {
     380          15 :             rValue >>= m_bRecommendPwd;
     381          15 :             m_bRORecommendPwd = bRO;
     382             :         }
     383          15 :         break;
     384             : 
     385             :         case PROPERTYHANDLE_CTRLCLICK_HYPERLINK:
     386             :         {
     387          15 :             rValue >>= m_bCtrlClickHyperlink;
     388          15 :             m_bROCtrlClickHyperlink = bRO;
     389             :         }
     390          15 :         break;
     391             : 
     392             :         case PROPERTYHANDLE_MACRO_SECLEVEL:
     393             :         {
     394          15 :             rValue >>= m_nSecLevel;
     395          15 :             m_bROSecLevel = bRO;
     396             :         }
     397          15 :         break;
     398             : 
     399             :         case PROPERTYHANDLE_MACRO_TRUSTEDAUTHORS:
     400             :         {
     401             :             // don't care about value here...
     402          15 :             m_bROTrustedAuthors = bRO;
     403             :         }
     404          15 :         break;
     405             : 
     406             :         case PROPERTYHANDLE_MACRO_DISABLE:
     407             :         {
     408          15 :             rValue >>= m_bDisableMacros;
     409          15 :             m_bRODisableMacros = bRO;
     410             :         }
     411          15 :         break;
     412             : 
     413             : 
     414             :         // xmlsec05 depricated
     415             :         case PROPERTYHANDLE_STAROFFICEBASIC:
     416             :         {
     417          15 :             sal_Int32 nMode = 0;
     418          15 :             rValue >>= nMode;
     419          15 :             m_eBasicMode = (EBasicSecurityMode)nMode;
     420          15 :             m_bROBasicMode = bRO;
     421             :         }
     422          15 :         break;
     423             :         case PROPERTYHANDLE_EXECUTEPLUGINS:
     424             :         {
     425          15 :             rValue >>= m_bExecutePlugins;
     426          15 :             m_bROExecutePlugins = bRO;
     427             :         }
     428          15 :         break;
     429             :         case PROPERTYHANDLE_WARNINGENABLED:
     430             :         {
     431          15 :             rValue >>= m_bWarning;
     432          15 :             m_bROWarning = bRO;
     433             :         }
     434          15 :         break;
     435             :         case PROPERTYHANDLE_CONFIRMATIONENABLED:
     436             :         {
     437          15 :             rValue >>= m_bConfirmation;
     438          15 :             m_bROConfirmation = bRO;
     439             :         }
     440          15 :         break;
     441             :         // xmlsec05 depricated
     442             : 
     443             : 
     444             :         #if OSL_DEBUG_LEVEL > 1
     445             :         default:
     446             :             DBG_ASSERT( false, "SvtSecurityOptions_Impl::SetProperty()\nUnkown property!\n" );
     447             :         #endif
     448             :     }
     449         225 : }
     450             : 
     451          15 : void SvtSecurityOptions_Impl::LoadAuthors( void )
     452             : {
     453          15 :     m_seqTrustedAuthors.realloc( 0 );       // first clear
     454          15 :     Sequence< OUString >    lAuthors = GetNodeNames( PROPERTYNAME_MACRO_TRUSTEDAUTHORS );
     455          15 :     sal_Int32               c1 = lAuthors.getLength();
     456          15 :     if( c1 )
     457             :     {
     458           0 :         sal_Int32               c2 = c1 * 3;                // 3 Properties inside Struct TrustedAuthor
     459           0 :         Sequence< OUString >    lAllAuthors( c2 );
     460             : 
     461             :         sal_Int32               i1;
     462             :         sal_Int32               i2;
     463           0 :         OUString                aSep( RTL_CONSTASCII_USTRINGPARAM( "/" ) );
     464           0 :         for( i1 = 0, i2 = 0 ; i1 < c1 ; ++i1 )
     465             :         {
     466           0 :             lAllAuthors[ i2 ] = PROPERTYNAME_MACRO_TRUSTEDAUTHORS + aSep + lAuthors[ i1 ] + aSep + PROPERTYNAME_TRUSTEDAUTHOR_SUBJECTNAME;
     467           0 :             ++i2;
     468           0 :             lAllAuthors[ i2 ] = PROPERTYNAME_MACRO_TRUSTEDAUTHORS + aSep + lAuthors[ i1 ] + aSep + PROPERTYNAME_TRUSTEDAUTHOR_SERIALNUMBER;
     469           0 :             ++i2;
     470           0 :             lAllAuthors[ i2 ] = PROPERTYNAME_MACRO_TRUSTEDAUTHORS + aSep + lAuthors[ i1 ] + aSep + PROPERTYNAME_TRUSTEDAUTHOR_RAWDATA;
     471           0 :             ++i2;
     472             :         }
     473             : 
     474           0 :         Sequence< Any >         lValues = GetProperties( lAllAuthors );
     475           0 :         if( lValues.getLength() == c2 )
     476             :         {
     477           0 :             comphelper::SequenceAsVector< SvtSecurityOptions::Certificate > v;
     478           0 :             SvtSecurityOptions::Certificate aCert( 3 );
     479           0 :             for( i1 = 0, i2 = 0 ; i1 < c1 ; ++i1 )
     480             :             {
     481           0 :                 lValues[ i2 ] >>= aCert[ 0 ];
     482           0 :                 ++i2;
     483           0 :                 lValues[ i2 ] >>= aCert[ 1 ];
     484           0 :                 ++i2;
     485           0 :                 lValues[ i2 ] >>= aCert[ 2 ];
     486           0 :                 ++i2;
     487             :                 // Filter out TrustedAuthor entries with empty RawData, which
     488             :                 // would cause an unexpected std::bad_alloc in
     489             :                 // SecurityEnvironment_NssImpl::createCertificateFromAscii and
     490             :                 // have been observed in the wild (fdo#55019):
     491           0 :                 if( !aCert[ 2 ].isEmpty() )
     492             :                 {
     493           0 :                     v.push_back( aCert );
     494             :                 }
     495             :             }
     496           0 :             m_seqTrustedAuthors = v.getAsConstList();
     497           0 :         }
     498          15 :     }
     499          15 : }
     500             : 
     501           0 : sal_Int32 SvtSecurityOptions_Impl::GetHandle( const OUString& rName )
     502             : {
     503             :     sal_Int32   nHandle;
     504             : 
     505           0 :     if( rName.compareToAscii( CSTR_SECUREURL ) == 0 )
     506           0 :         nHandle = PROPERTYHANDLE_SECUREURL;
     507           0 :     else if( rName.compareToAscii( CSTR_DOCWARN_SAVEORSEND ) == 0 )
     508           0 :         nHandle = PROPERTYHANDLE_DOCWARN_SAVEORSEND;
     509           0 :     else if( rName.compareToAscii( CSTR_DOCWARN_SIGNING ) == 0 )
     510           0 :         nHandle = PROPERTYHANDLE_DOCWARN_SIGNING;
     511           0 :     else if( rName.compareToAscii( CSTR_DOCWARN_PRINT ) == 0 )
     512           0 :         nHandle = PROPERTYHANDLE_DOCWARN_PRINT;
     513           0 :     else if( rName.compareToAscii( CSTR_DOCWARN_CREATEPDF ) == 0 )
     514           0 :         nHandle = PROPERTYHANDLE_DOCWARN_CREATEPDF;
     515           0 :     else if( rName.compareToAscii( CSTR_DOCWARN_REMOVEPERSONALINFO ) == 0 )
     516           0 :         nHandle = PROPERTYHANDLE_DOCWARN_REMOVEPERSONALINFO;
     517           0 :     else if( rName.compareToAscii( CSTR_DOCWARN_RECOMMENDPASSWORD ) == 0 )
     518           0 :         nHandle = PROPERTYHANDLE_DOCWARN_RECOMMENDPASSWORD;
     519           0 :     else if( rName.compareToAscii( CSTR_CTRLCLICK_HYPERLINK ) == 0 )
     520           0 :         nHandle = PROPERTYHANDLE_CTRLCLICK_HYPERLINK;
     521           0 :     else if( rName.compareToAscii( CSTR_MACRO_SECLEVEL ) == 0 )
     522           0 :         nHandle = PROPERTYHANDLE_MACRO_SECLEVEL;
     523           0 :     else if( rName.compareToAscii( CSTR_MACRO_TRUSTEDAUTHORS ) == 0 )
     524           0 :         nHandle = PROPERTYHANDLE_MACRO_TRUSTEDAUTHORS;
     525           0 :     else if( rName.compareToAscii( CSTR_MACRO_DISABLE ) == 0 )
     526           0 :         nHandle = PROPERTYHANDLE_MACRO_DISABLE;
     527             : 
     528             :     // xmlsec05 depricated
     529           0 :     else if( rName == PROPERTYNAME_STAROFFICEBASIC )
     530           0 :         nHandle = PROPERTYHANDLE_STAROFFICEBASIC;
     531           0 :     else if( rName == PROPERTYNAME_EXECUTEPLUGINS )
     532           0 :         nHandle = PROPERTYHANDLE_EXECUTEPLUGINS;
     533           0 :     else if( rName == PROPERTYNAME_WARNINGENABLED )
     534           0 :         nHandle = PROPERTYHANDLE_WARNINGENABLED;
     535           0 :     else if( rName == PROPERTYNAME_CONFIRMATIONENABLED )
     536           0 :         nHandle = PROPERTYHANDLE_CONFIRMATIONENABLED;
     537             :     // xmlsec05 depricated
     538             : 
     539             :     else
     540           0 :         nHandle = PROPERTYHANDLE_INVALID;
     541             : 
     542           0 :     return nHandle;
     543             : }
     544             : 
     545         148 : bool SvtSecurityOptions_Impl::GetOption( SvtSecurityOptions::EOption eOption, sal_Bool*& rpValue, sal_Bool*& rpRO )
     546             : {
     547         148 :     switch( eOption )
     548             :     {
     549             :         case SvtSecurityOptions::E_DOCWARN_SAVEORSEND:
     550           0 :             rpValue = &m_bSaveOrSend;
     551           0 :             rpRO = &m_bROSaveOrSend;
     552           0 :             break;
     553             :         case SvtSecurityOptions::E_DOCWARN_SIGNING:
     554           0 :             rpValue = &m_bSigning;
     555           0 :             rpRO = &m_bROSigning;
     556           0 :             break;
     557             :         case SvtSecurityOptions::E_DOCWARN_PRINT:
     558           0 :             rpValue = &m_bPrint;
     559           0 :             rpRO = &m_bROPrint;
     560           0 :             break;
     561             :         case SvtSecurityOptions::E_DOCWARN_CREATEPDF:
     562           0 :             rpValue = &m_bCreatePDF;
     563           0 :             rpRO = &m_bROCreatePDF;
     564           0 :             break;
     565             :         case SvtSecurityOptions::E_DOCWARN_REMOVEPERSONALINFO:
     566           4 :             rpValue = &m_bRemoveInfo;
     567           4 :             rpRO = &m_bRORemoveInfo;
     568           4 :             break;
     569             :         case SvtSecurityOptions::E_DOCWARN_RECOMMENDPASSWORD:
     570           0 :             rpValue = &m_bRecommendPwd;
     571           0 :             rpRO = &m_bRORecommendPwd;
     572           0 :             break;
     573             :         case SvtSecurityOptions::E_CTRLCLICK_HYPERLINK:
     574         144 :             rpValue = &m_bCtrlClickHyperlink;
     575         144 :             rpRO = &m_bROCtrlClickHyperlink;
     576         144 :             break;
     577             :         default:
     578           0 :             rpValue = NULL;
     579           0 :             rpRO = NULL;
     580           0 :             break;
     581             :     }
     582             : 
     583         148 :     return rpValue != NULL;
     584             : }
     585             : 
     586           0 : void SvtSecurityOptions_Impl::Notify( const Sequence< OUString >& seqPropertyNames )
     587             : {
     588             :     // Use given list of updated properties to get his values from configuration directly!
     589           0 :     Sequence< Any >         seqValues = GetProperties( seqPropertyNames );
     590           0 :     Sequence< sal_Bool >    seqRO = GetReadOnlyStates( seqPropertyNames );
     591             :     // Safe impossible cases.
     592             :     // We need values from ALL notified configuration keys.
     593             :     DBG_ASSERT( !(seqPropertyNames.getLength()!=seqValues.getLength()), "SvtSecurityOptions_Impl::Notify()\nI miss some values of configuration keys!\n" );
     594             :     // Step over list of property names and get right value from coreesponding value list to set it on internal members!
     595           0 :     sal_Int32               nCount = seqPropertyNames.getLength();
     596           0 :     for( sal_Int32 nProperty = 0 ; nProperty < nCount ; ++nProperty )
     597           0 :         SetProperty( GetHandle( seqPropertyNames[ nProperty ] ), seqValues[ nProperty ], seqRO[ nProperty ] );
     598             : 
     599             :     // read set of trusted authors separately
     600           0 :     LoadAuthors();
     601           0 : }
     602             : 
     603           0 : void SvtSecurityOptions_Impl::Commit()
     604             : {
     605             :     // Get names of supported properties, create a list for values and copy current values to it.
     606           0 :     Sequence< OUString >    lOrgNames = GetPropertyNames();
     607           0 :     sal_Int32               nOrgCount = lOrgNames.getLength();
     608             : 
     609           0 :     Sequence< OUString >    lNames(nOrgCount);
     610           0 :     Sequence< Any >         lValues(nOrgCount);
     611           0 :     sal_Int32               nRealCount = 0;
     612             :     bool                    bDone;
     613             : 
     614           0 :     ClearNodeSet( PROPERTYNAME_MACRO_TRUSTEDAUTHORS );
     615             : 
     616           0 :     for( sal_Int32 nProperty = 0 ; nProperty < nOrgCount ; ++nProperty )
     617             :     {
     618           0 :         switch( nProperty )
     619             :         {
     620             :             case PROPERTYHANDLE_SECUREURL:
     621             :             {
     622           0 :                 bDone = !m_bROSecureURLs;
     623           0 :                 if( bDone )
     624             :                 {
     625           0 :                     Sequence< OUString >    lURLs( m_seqSecureURLs );
     626           0 :                     SvtPathOptions          aOpt;
     627           0 :                     sal_Int32               nURLsCnt = lURLs.getLength();
     628           0 :                     for( sal_Int32 nItem = 0 ; nItem < nURLsCnt ; ++nItem )
     629           0 :                         lURLs[ nItem ] = aOpt.UseVariable( lURLs[ nItem ] );
     630           0 :                     lValues[ nRealCount ] <<= lURLs;
     631             :                 }
     632             :             }
     633           0 :             break;
     634             : 
     635             :             case PROPERTYHANDLE_DOCWARN_SAVEORSEND:
     636             :             {
     637           0 :                 bDone = !m_bROSaveOrSend;
     638           0 :                 if( bDone )
     639           0 :                     lValues[ nRealCount ] <<= m_bSaveOrSend;
     640             :             }
     641           0 :             break;
     642             : 
     643             :             case PROPERTYHANDLE_DOCWARN_SIGNING:
     644             :             {
     645           0 :                 bDone = !m_bROSigning;
     646           0 :                 if( bDone )
     647           0 :                     lValues[ nRealCount ] <<= m_bSigning;
     648             :             }
     649           0 :             break;
     650             : 
     651             :             case PROPERTYHANDLE_DOCWARN_PRINT:
     652             :             {
     653           0 :                 bDone = !m_bROPrint;
     654           0 :                 if( bDone )
     655           0 :                     lValues[ nRealCount ] <<= m_bPrint;
     656             :             }
     657           0 :             break;
     658             : 
     659             :             case PROPERTYHANDLE_DOCWARN_CREATEPDF:
     660             :             {
     661           0 :                 bDone = !m_bROCreatePDF;
     662           0 :                 if( bDone )
     663           0 :                     lValues[ nRealCount ] <<= m_bCreatePDF;
     664             :             }
     665           0 :             break;
     666             : 
     667             :             case PROPERTYHANDLE_DOCWARN_REMOVEPERSONALINFO:
     668             :             {
     669           0 :                 bDone = !m_bRORemoveInfo;
     670           0 :                 if( bDone )
     671           0 :                     lValues[ nRealCount ] <<= m_bRemoveInfo;
     672             :             }
     673           0 :             break;
     674             : 
     675             :             case PROPERTYHANDLE_DOCWARN_RECOMMENDPASSWORD:
     676             :             {
     677           0 :                 bDone = !m_bRORecommendPwd;
     678           0 :                 if( bDone )
     679           0 :                     lValues[ nRealCount ] <<= m_bRecommendPwd;
     680             :             }
     681           0 :             break;
     682             : 
     683             :             case PROPERTYHANDLE_CTRLCLICK_HYPERLINK:
     684             :             {
     685           0 :                 bDone = !m_bROCtrlClickHyperlink;
     686           0 :                 if( bDone )
     687           0 :                     lValues[ nRealCount ] <<= m_bCtrlClickHyperlink;
     688             :             }
     689           0 :             break;
     690             : 
     691             :             case PROPERTYHANDLE_MACRO_SECLEVEL:
     692             :             {
     693           0 :                 bDone = !m_bROSecLevel;
     694           0 :                 if( bDone )
     695           0 :                     lValues[ nRealCount ] <<= m_nSecLevel;
     696             :             }
     697           0 :             break;
     698             : 
     699             :             case PROPERTYHANDLE_MACRO_TRUSTEDAUTHORS:
     700             :             {
     701           0 :                 bDone = !m_bROTrustedAuthors;
     702           0 :                 if( bDone )
     703             :                 {
     704           0 :                     sal_Int32   nCnt = m_seqTrustedAuthors.getLength();
     705           0 :                     if( nCnt )
     706             :                     {
     707           0 :                         String  s;
     708           0 :                         s.AppendAscii( CSTR_MACRO_TRUSTEDAUTHORS );
     709           0 :                         s.AppendAscii( "/a" );
     710             : 
     711           0 :                         Sequence< Sequence< com::sun::star::beans::PropertyValue > > lPropertyValuesSeq( nCnt );
     712           0 :                         for( sal_Int32 i = 0 ; i < nCnt ; ++i )
     713             :                         {
     714           0 :                             rtl::OUString aPrefix = rtl::OUStringBuffer(s).append(i).append('/').makeStringAndClear();
     715           0 :                             Sequence< com::sun::star::beans::PropertyValue >    lPropertyValues( 3 );
     716           0 :                             lPropertyValues[ 0 ].Name = aPrefix + PROPERTYNAME_TRUSTEDAUTHOR_SUBJECTNAME;
     717           0 :                             lPropertyValues[ 0 ].Value <<= m_seqTrustedAuthors[ i ][0];
     718           0 :                             lPropertyValues[ 1 ].Name = aPrefix + PROPERTYNAME_TRUSTEDAUTHOR_SERIALNUMBER;
     719           0 :                             lPropertyValues[ 1 ].Value <<= m_seqTrustedAuthors[ i ][1];
     720           0 :                             lPropertyValues[ 2 ].Name = aPrefix + PROPERTYNAME_TRUSTEDAUTHOR_RAWDATA;
     721           0 :                             lPropertyValues[ 2 ].Value <<= m_seqTrustedAuthors[ i ][2];
     722             : 
     723             : 
     724           0 :                             SetSetProperties( PROPERTYNAME_MACRO_TRUSTEDAUTHORS, lPropertyValues );
     725           0 :                         }
     726             : 
     727           0 :                         bDone = false;      // because we save in loop above!
     728             :                     }
     729             :                     else
     730           0 :                         bDone = false;
     731             :                 }
     732             :             }
     733           0 :             break;
     734             : 
     735             :             case PROPERTYHANDLE_MACRO_DISABLE:
     736             :             {
     737           0 :                 bDone = !m_bRODisableMacros;
     738           0 :                 if( bDone )
     739           0 :                     lValues[ nRealCount ] <<= (sal_Bool)m_bDisableMacros;
     740             :             }
     741           0 :             break;
     742             : 
     743             : 
     744             :             // xmlsec05 depricated
     745             :             case PROPERTYHANDLE_STAROFFICEBASIC:
     746             :             {
     747           0 :                 bDone = !m_bROBasicMode;
     748           0 :                 if( bDone )
     749           0 :                     lValues[ nRealCount ] <<= (sal_Int32)m_eBasicMode;
     750             :             }
     751           0 :             break;
     752             :             case PROPERTYHANDLE_EXECUTEPLUGINS:
     753             :             {
     754           0 :                 bDone = !m_bROExecutePlugins;
     755           0 :                 if( bDone )
     756           0 :                     lValues[ nRealCount ] <<= m_bExecutePlugins;
     757             :             }
     758           0 :             break;
     759             :             case PROPERTYHANDLE_WARNINGENABLED:
     760             :             {
     761           0 :                 bDone = !m_bROWarning;
     762           0 :                 if( bDone )
     763           0 :                     lValues[ nRealCount ] <<= m_bWarning;
     764             :             }
     765           0 :             break;
     766             :             case PROPERTYHANDLE_CONFIRMATIONENABLED:
     767             :             {
     768           0 :                 bDone = !m_bROConfirmation;
     769           0 :                 if( bDone )
     770           0 :                     lValues[ nRealCount ] <<= m_bConfirmation;
     771             :             }
     772           0 :             break;
     773             :             // xmlsec05 depricated
     774             : 
     775             : 
     776             :             default:
     777           0 :                 bDone = false;
     778             :         }
     779             : 
     780           0 :         if( bDone )
     781             :         {
     782           0 :             lNames[ nRealCount ] = lOrgNames[ nProperty ];
     783           0 :             ++nRealCount;
     784             :         }
     785             :     }
     786             :     // Set properties in configuration.
     787           0 :     lNames.realloc(nRealCount);
     788           0 :     lValues.realloc(nRealCount);
     789           0 :     PutProperties( lNames, lValues );
     790           0 : }
     791             : 
     792           0 : sal_Bool SvtSecurityOptions_Impl::IsReadOnly( SvtSecurityOptions::EOption eOption ) const
     793             : {
     794             :     sal_Bool    bReadonly;
     795           0 :     switch(eOption)
     796             :     {
     797             :         case SvtSecurityOptions::E_SECUREURLS :
     798           0 :             bReadonly = m_bROSecureURLs;
     799           0 :             break;
     800             :         case SvtSecurityOptions::E_DOCWARN_SAVEORSEND:
     801           0 :             bReadonly = m_bROSaveOrSend;
     802           0 :             break;
     803             :         case SvtSecurityOptions::E_DOCWARN_SIGNING:
     804           0 :             bReadonly = m_bROSigning;
     805           0 :             break;
     806             :         case SvtSecurityOptions::E_DOCWARN_PRINT:
     807           0 :             bReadonly = m_bROPrint;
     808           0 :             break;
     809             :         case SvtSecurityOptions::E_DOCWARN_CREATEPDF:
     810           0 :             bReadonly = m_bROCreatePDF;
     811           0 :             break;
     812             :         case SvtSecurityOptions::E_DOCWARN_REMOVEPERSONALINFO:
     813           0 :             bReadonly = m_bRORemoveInfo;
     814           0 :             break;
     815             :         case SvtSecurityOptions::E_DOCWARN_RECOMMENDPASSWORD:
     816           0 :             bReadonly = m_bRORecommendPwd;
     817           0 :             break;
     818             :         case SvtSecurityOptions::E_MACRO_SECLEVEL:
     819           0 :             bReadonly = m_bROSecLevel;
     820           0 :             break;
     821             :         case SvtSecurityOptions::E_MACRO_TRUSTEDAUTHORS:
     822           0 :             bReadonly = m_bROTrustedAuthors;
     823           0 :             break;
     824             :         case SvtSecurityOptions::E_MACRO_DISABLE:
     825           0 :             bReadonly = m_bRODisableMacros;
     826           0 :             break;
     827             :         case SvtSecurityOptions::E_CTRLCLICK_HYPERLINK:
     828           0 :             bReadonly = m_bROCtrlClickHyperlink;
     829           0 :             break;
     830             : 
     831             : 
     832             :         // xmlsec05 depricated
     833             :         case SvtSecurityOptions::E_BASICMODE:
     834           0 :             bReadonly = m_bROBasicMode;
     835           0 :             break;
     836             :         case SvtSecurityOptions::E_EXECUTEPLUGINS:
     837           0 :             bReadonly = m_bROExecutePlugins;
     838           0 :             break;
     839             :         case SvtSecurityOptions::E_WARNING:
     840           0 :             bReadonly = m_bROWarning;
     841           0 :             break;
     842             :         case SvtSecurityOptions::E_CONFIRMATION:
     843           0 :             bReadonly = m_bROConfirmation;
     844           0 :             break;
     845             :         // xmlsec05 depricated
     846             : 
     847             : 
     848             :         default:
     849           0 :             bReadonly = sal_True;
     850             :     }
     851             : 
     852           0 :     return bReadonly;
     853             : }
     854             : 
     855           0 : Sequence< OUString > SvtSecurityOptions_Impl::GetSecureURLs() const
     856             : {
     857           0 :     return m_seqSecureURLs;
     858             : }
     859             : 
     860           0 : void SvtSecurityOptions_Impl::SetSecureURLs( const Sequence< OUString >& seqURLList )
     861             : {
     862             :     DBG_ASSERT(!m_bROSecureURLs, "SvtSecurityOptions_Impl::SetSecureURLs()\nYou tried to write on a readonly value!\n");
     863           0 :     if (!m_bROSecureURLs && m_seqSecureURLs!=seqURLList)
     864             :     {
     865           0 :         m_seqSecureURLs = seqURLList;
     866           0 :         SetModified();
     867             :     }
     868           0 : }
     869             : 
     870           0 : sal_Bool SvtSecurityOptions_Impl::IsSecureURL(  const   OUString&   sURL    ,
     871             :                                                 const   OUString&   sReferer) const
     872             : {
     873           0 :     sal_Bool bState = sal_False;
     874             : 
     875             :     // Check for uncritical protocols first
     876             :     // All protocols different from "macro..." and "slot..." are secure per definition and must not be checked.
     877             :     // "macro://#..." means AppBasic macros that are considered safe
     878           0 :     INetURLObject   aURL        ( sURL );
     879           0 :     INetProtocol    aProtocol   = aURL.GetProtocol();
     880             : 
     881             :     // All other URLs must checked in combination with referer and internal information about security
     882           0 :     if ( (aProtocol != INET_PROT_MACRO && aProtocol !=  INET_PROT_SLOT) ||
     883           0 :          aURL.GetMainURL( INetURLObject::NO_DECODE ).matchIgnoreAsciiCaseAsciiL( "macro:///", 9 ) == 0)
     884             :     {
     885             :         // security check only for "macro" ( without app basic ) or "slot" protocols
     886           0 :         bState = sal_True;
     887             :     }
     888             :     else
     889             :     {
     890             :         //  check list of allowed URL patterns
     891             :         // Trusted referer given?
     892             :         // NO  => bState will be false per default
     893             :         // YES => search for it in our internal url list
     894           0 :         if( !sReferer.isEmpty() )
     895             :         {
     896             :             // Search in internal list
     897           0 :             ::rtl::OUString sRef = sReferer.toAsciiLowerCase();
     898           0 :             sal_uInt32 nCount = m_seqSecureURLs.getLength();
     899           0 :             for( sal_uInt32 nItem=0; nItem<nCount; ++nItem )
     900             :             {
     901           0 :                 OUString sCheckURL = m_seqSecureURLs[nItem].toAsciiLowerCase();
     902           0 :                 sCheckURL += OUString(RTL_CONSTASCII_USTRINGPARAM("*"));
     903           0 :                 if( WildCard( sCheckURL ).Matches( sRef ) == sal_True )
     904             :                 {
     905           0 :                     bState = sal_True;
     906             :                     break;
     907             :                 }
     908           0 :             }
     909             : 
     910           0 :             if ( !bState )
     911           0 :                 bState = sRef.compareToAscii("private:user") == COMPARE_EQUAL;
     912             :         }
     913             :     }
     914             : 
     915             :     // Return result of operation.
     916           0 :     return bState;
     917             : }
     918             : 
     919           0 : inline sal_Int32 SvtSecurityOptions_Impl::GetMacroSecurityLevel() const
     920             : {
     921           0 :     return m_nSecLevel;
     922             : }
     923             : 
     924         584 : inline sal_Bool SvtSecurityOptions_Impl::IsMacroDisabled() const
     925             : {
     926         584 :     return m_bDisableMacros;
     927             : }
     928             : 
     929           0 : void SvtSecurityOptions_Impl::SetMacroSecurityLevel( sal_Int32 _nLevel )
     930             : {
     931           0 :     if( !m_bROSecLevel )
     932             :     {
     933           0 :         if( _nLevel > 3 || _nLevel < 0 )
     934           0 :             _nLevel = 3;
     935             : 
     936           0 :         if( m_nSecLevel != _nLevel )
     937             :         {
     938           0 :             m_nSecLevel = _nLevel;
     939           0 :             SetModified();
     940             :         }
     941             :     }
     942           0 : }
     943             : 
     944           0 : Sequence< SvtSecurityOptions::Certificate > SvtSecurityOptions_Impl::GetTrustedAuthors() const
     945             : {
     946           0 :     return m_seqTrustedAuthors;
     947             : }
     948             : 
     949           0 : void SvtSecurityOptions_Impl::SetTrustedAuthors( const Sequence< SvtSecurityOptions::Certificate >& rAuthors )
     950             : {
     951             :     DBG_ASSERT(!m_bROTrustedAuthors, "SvtSecurityOptions_Impl::SetTrustedAuthors()\nYou tried to write on a readonly value!\n");
     952           0 :     if( !m_bROTrustedAuthors && rAuthors != m_seqTrustedAuthors )
     953             :     {
     954           0 :         m_seqTrustedAuthors = rAuthors;
     955           0 :         SetModified();
     956             :     }
     957           0 : }
     958             : 
     959         148 : sal_Bool SvtSecurityOptions_Impl::IsOptionSet( SvtSecurityOptions::EOption eOption ) const
     960             : {
     961             :     sal_Bool*   pValue;
     962             :     sal_Bool*   pRO;
     963         148 :     sal_Bool    bRet = sal_False;
     964             : 
     965         148 :     if( ( const_cast< SvtSecurityOptions_Impl* >( this ) )->GetOption( eOption, pValue, pRO ) )
     966         148 :         bRet = *pValue;
     967             : 
     968         148 :     return bRet;
     969             : }
     970             : 
     971           0 : sal_Bool SvtSecurityOptions_Impl::SetOption( SvtSecurityOptions::EOption eOption, sal_Bool bValue )
     972             : {
     973             :     sal_Bool*   pValue;
     974             :     sal_Bool*   pRO;
     975           0 :     sal_Bool    bRet = sal_False;
     976             : 
     977           0 :     if( GetOption( eOption, pValue, pRO ) )
     978             :     {
     979           0 :         if( !*pRO )
     980             :         {
     981           0 :             bRet = sal_True;
     982           0 :             if( *pValue != bValue )
     983             :             {
     984           0 :                 *pValue = bValue;
     985           0 :                 SetModified();
     986             :             }
     987             :         }
     988             :     }
     989             : 
     990           0 :     return bRet;
     991             : }
     992             : 
     993           0 : sal_Bool SvtSecurityOptions_Impl::IsOptionEnabled( SvtSecurityOptions::EOption eOption ) const
     994             : {
     995             :     sal_Bool*   pValue;
     996             :     sal_Bool*   pRO;
     997           0 :     sal_Bool    bRet = sal_False;
     998             : 
     999           0 :     if( ( const_cast< SvtSecurityOptions_Impl* >( this ) )->GetOption( eOption, pValue, pRO ) )
    1000           0 :         bRet = !*pRO;
    1001             : 
    1002           0 :     return bRet;
    1003             : }
    1004             : 
    1005          15 : Sequence< OUString > SvtSecurityOptions_Impl::GetPropertyNames()
    1006             : {
    1007             :     // Build static list of configuration key names.
    1008             :     const OUString pProperties[] =
    1009             :     {
    1010             :         PROPERTYNAME_SECUREURL,
    1011             :         PROPERTYNAME_STAROFFICEBASIC,
    1012             :         PROPERTYNAME_EXECUTEPLUGINS,
    1013             :         PROPERTYNAME_WARNINGENABLED,
    1014             :         PROPERTYNAME_CONFIRMATIONENABLED,
    1015             :         PROPERTYNAME_DOCWARN_SAVEORSEND,
    1016             :         PROPERTYNAME_DOCWARN_SIGNING,
    1017             :         PROPERTYNAME_DOCWARN_PRINT,
    1018             :         PROPERTYNAME_DOCWARN_CREATEPDF,
    1019             :         PROPERTYNAME_DOCWARN_REMOVEPERSONALINFO,
    1020             :         PROPERTYNAME_DOCWARN_RECOMMENDPASSWORD,
    1021             :         PROPERTYNAME_CTRLCLICK_HYPERLINK,
    1022             :         PROPERTYNAME_MACRO_SECLEVEL,
    1023             :         PROPERTYNAME_MACRO_TRUSTEDAUTHORS,
    1024             :         PROPERTYNAME_MACRO_DISABLE
    1025         240 :     };
    1026             :     // Initialize return sequence with these list ...
    1027          15 :     const Sequence< OUString > seqPropertyNames( pProperties, PROPERTYCOUNT );
    1028             :     // ... and return it.
    1029         240 :     return seqPropertyNames;
    1030             : }
    1031             : 
    1032             : //*****************************************************************************************************************
    1033             : //  initialize static member
    1034             : //  DON'T DO IT IN YOUR HEADER!
    1035             : //  see definition for further informations
    1036             : //*****************************************************************************************************************
    1037             : SvtSecurityOptions_Impl*    SvtSecurityOptions::m_pDataContainer    = NULL  ;
    1038             : sal_Int32                   SvtSecurityOptions::m_nRefCount         = 0     ;
    1039             : 
    1040         747 : SvtSecurityOptions::SvtSecurityOptions()
    1041             : {
    1042             :     // Global access, must be guarded (multithreading!).
    1043         747 :     MutexGuard aGuard( GetInitMutex() );
    1044             :     // Increase ouer refcount ...
    1045         747 :     ++m_nRefCount;
    1046             :     // ... and initialize ouer data container only if it not already exist!
    1047         747 :     if( m_pDataContainer == NULL )
    1048             :     {
    1049             :         RTL_LOGFILE_CONTEXT(aLog, "unotools ( ??? ) ::SvtSecurityOptions_Impl::ctor()");
    1050          15 :         m_pDataContainer = new SvtSecurityOptions_Impl;
    1051             : 
    1052          15 :         ItemHolder1::holdConfigItem(E_SECURITYOPTIONS);
    1053         747 :     }
    1054         747 : }
    1055             : 
    1056        1509 : SvtSecurityOptions::~SvtSecurityOptions()
    1057             : {
    1058             :     // Global access, must be guarded (multithreading!)
    1059         747 :     MutexGuard aGuard( GetInitMutex() );
    1060             :     // Decrease ouer refcount.
    1061         747 :     --m_nRefCount;
    1062             :     // If last instance was deleted ...
    1063             :     // we must destroy ouer static data container!
    1064         747 :     if( m_nRefCount <= 0 )
    1065             :     {
    1066          15 :         delete m_pDataContainer;
    1067          15 :         m_pDataContainer = NULL;
    1068         747 :     }
    1069         762 : }
    1070             : 
    1071           0 : sal_Bool SvtSecurityOptions::IsReadOnly( EOption eOption ) const
    1072             : {
    1073           0 :     MutexGuard aGuard( GetInitMutex() );
    1074           0 :     return m_pDataContainer->IsReadOnly(eOption);
    1075             : }
    1076             : 
    1077           0 : Sequence< OUString > SvtSecurityOptions::GetSecureURLs() const
    1078             : {
    1079           0 :     MutexGuard aGuard( GetInitMutex() );
    1080           0 :     return m_pDataContainer->GetSecureURLs();
    1081             : }
    1082             : 
    1083           0 : void SvtSecurityOptions::SetSecureURLs( const Sequence< OUString >& seqURLList )
    1084             : {
    1085           0 :     MutexGuard aGuard( GetInitMutex() );
    1086           0 :     m_pDataContainer->SetSecureURLs( seqURLList );
    1087           0 : }
    1088             : 
    1089           0 : sal_Bool SvtSecurityOptions::IsSecureURL(   const   OUString&   sURL        ,
    1090             :                                             const   OUString&   sReferer    ) const
    1091             : {
    1092           0 :     MutexGuard aGuard( GetInitMutex() );
    1093           0 :     return m_pDataContainer->IsSecureURL( sURL, sReferer );
    1094             : }
    1095             : 
    1096           0 : sal_Int32 SvtSecurityOptions::GetMacroSecurityLevel() const
    1097             : {
    1098           0 :     MutexGuard aGuard( GetInitMutex() );
    1099           0 :     return m_pDataContainer->GetMacroSecurityLevel();
    1100             : }
    1101             : 
    1102           0 : void SvtSecurityOptions::SetMacroSecurityLevel( sal_Int32 _nLevel )
    1103             : {
    1104           0 :     MutexGuard aGuard( GetInitMutex() );
    1105           0 :     m_pDataContainer->SetMacroSecurityLevel( _nLevel );
    1106           0 : }
    1107             : 
    1108         584 : sal_Bool SvtSecurityOptions::IsMacroDisabled() const
    1109             : {
    1110         584 :     MutexGuard aGuard( GetInitMutex() );
    1111         584 :     return m_pDataContainer->IsMacroDisabled();
    1112             : }
    1113             : 
    1114           0 : Sequence< SvtSecurityOptions::Certificate > SvtSecurityOptions::GetTrustedAuthors() const
    1115             : {
    1116           0 :     MutexGuard aGuard( GetInitMutex() );
    1117           0 :     return m_pDataContainer->GetTrustedAuthors();
    1118             : }
    1119             : 
    1120           0 : void SvtSecurityOptions::SetTrustedAuthors( const Sequence< Certificate >& rAuthors )
    1121             : {
    1122           0 :     MutexGuard aGuard( GetInitMutex() );
    1123           0 :     m_pDataContainer->SetTrustedAuthors( rAuthors );
    1124           0 : }
    1125             : 
    1126         148 : bool SvtSecurityOptions::IsOptionSet( EOption eOption ) const
    1127             : {
    1128         148 :     MutexGuard aGuard( GetInitMutex() );
    1129         148 :     return m_pDataContainer->IsOptionSet( eOption );
    1130             : }
    1131             : 
    1132           0 : bool SvtSecurityOptions::SetOption( EOption eOption, bool bValue )
    1133             : {
    1134           0 :     MutexGuard aGuard( GetInitMutex() );
    1135           0 :     return m_pDataContainer->SetOption( eOption, bValue );
    1136             : }
    1137             : 
    1138           0 : bool SvtSecurityOptions::IsOptionEnabled( EOption eOption ) const
    1139             : {
    1140           0 :     MutexGuard aGuard( GetInitMutex() );
    1141           0 :     return m_pDataContainer->IsOptionEnabled( eOption );
    1142             : }
    1143             : 
    1144             : namespace
    1145             : {
    1146             :     class theSecurityOptionsMutex : public rtl::Static<osl::Mutex, theSecurityOptionsMutex>{};
    1147             : }
    1148             : 
    1149        2226 : Mutex& SvtSecurityOptions::GetInitMutex()
    1150             : {
    1151        2226 :     return theSecurityOptionsMutex::get();
    1152             : }
    1153             : 
    1154             : 
    1155             : 
    1156             : 
    1157             : // xmlsec05 depricated
    1158             : 
    1159           0 : EBasicSecurityMode SvtSecurityOptions_Impl::GetBasicMode() const
    1160             : {
    1161           0 :     return m_eBasicMode;
    1162             : }
    1163             : 
    1164           0 : void SvtSecurityOptions_Impl::SetBasicMode( EBasicSecurityMode eMode )
    1165             : {
    1166             :     DBG_ASSERT(!m_bROBasicMode, "SvtSecurityOptions_Impl::SetBasicMode()\nYou tried to write on a readonly value!\n");
    1167           0 :     if (!m_bROBasicMode && m_eBasicMode!=eMode)
    1168             :     {
    1169           0 :         m_eBasicMode = eMode;
    1170           0 :         SetModified();
    1171             :     }
    1172           0 : }
    1173             : 
    1174           0 : sal_Bool SvtSecurityOptions_Impl::IsExecutePlugins() const
    1175             : {
    1176           0 :     return m_bExecutePlugins;
    1177             : }
    1178             : 
    1179           0 : void SvtSecurityOptions_Impl::SetExecutePlugins( sal_Bool bSet )
    1180             : {
    1181             :     DBG_ASSERT(!m_bROExecutePlugins, "SvtSecurityOptions_Impl::SetExecutePlugins()\nYou tried to write on a readonly value!\n");
    1182           0 :     if (!m_bROExecutePlugins && m_bExecutePlugins!=bSet)
    1183             :     {
    1184           0 :         m_bExecutePlugins = bSet;
    1185           0 :         SetModified();
    1186             :     }
    1187           0 : }
    1188             : 
    1189           0 : sal_Bool SvtSecurityOptions_Impl::IsWarningEnabled() const
    1190             : {
    1191           0 :     return m_bWarning;
    1192             : }
    1193             : 
    1194           0 : void SvtSecurityOptions_Impl::SetWarningEnabled( sal_Bool bSet )
    1195             : {
    1196             :     DBG_ASSERT(!m_bROWarning, "SvtSecurityOptions_Impl::SetWarningEnabled()\nYou tried to write on a readonly value!\n");
    1197           0 :     if (!m_bROWarning && m_bWarning!=bSet)
    1198             :     {
    1199           0 :         m_bWarning = bSet;
    1200           0 :         SetModified();
    1201             :     }
    1202           0 : }
    1203             : 
    1204           0 : sal_Bool SvtSecurityOptions_Impl::IsConfirmationEnabled() const
    1205             : {
    1206           0 :     return m_bConfirmation;
    1207             : }
    1208             : 
    1209           0 : void SvtSecurityOptions_Impl::SetConfirmationEnabled( sal_Bool bSet )
    1210             : {
    1211             :     DBG_ASSERT(!m_bROConfirmation, "SvtSecurityOptions_Impl::SetConfirmationEnabled()\nYou tried to write on a readonly value!\n");
    1212           0 :     if (!m_bROConfirmation && m_bConfirmation!=bSet)
    1213             :     {
    1214           0 :         m_bConfirmation = bSet;
    1215           0 :         SetModified();
    1216             :     }
    1217           0 : }
    1218             : 
    1219             : 
    1220           0 : sal_Bool SvtSecurityOptions::IsExecutePlugins() const
    1221             : {
    1222           0 :     MutexGuard aGuard( GetInitMutex() );
    1223           0 :     return m_pDataContainer->IsExecutePlugins();
    1224             : }
    1225             : 
    1226           0 : void SvtSecurityOptions::SetExecutePlugins( sal_Bool bSet )
    1227             : {
    1228           0 :     MutexGuard aGuard( GetInitMutex() );
    1229           0 :     m_pDataContainer->SetExecutePlugins( bSet );
    1230           0 : }
    1231             : 
    1232           0 : sal_Bool SvtSecurityOptions::IsWarningEnabled() const
    1233             : {
    1234           0 :     MutexGuard aGuard( GetInitMutex() );
    1235           0 :     return m_pDataContainer->IsWarningEnabled();
    1236             : }
    1237             : 
    1238           0 : void SvtSecurityOptions::SetWarningEnabled( sal_Bool bSet )
    1239             : {
    1240           0 :     MutexGuard aGuard( GetInitMutex() );
    1241           0 :     m_pDataContainer->SetWarningEnabled( bSet );
    1242           0 : }
    1243             : 
    1244           0 : sal_Bool SvtSecurityOptions::IsConfirmationEnabled() const
    1245             : {
    1246           0 :     MutexGuard aGuard( GetInitMutex() );
    1247           0 :     return m_pDataContainer->IsConfirmationEnabled();
    1248             : }
    1249             : 
    1250           0 : void SvtSecurityOptions::SetConfirmationEnabled( sal_Bool bSet )
    1251             : {
    1252           0 :     MutexGuard aGuard( GetInitMutex() );
    1253           0 :     m_pDataContainer->SetConfirmationEnabled( bSet );
    1254           0 : }
    1255             : 
    1256           0 : void SvtSecurityOptions::SetBasicMode( EBasicSecurityMode eMode )
    1257             : {
    1258           0 :     MutexGuard aGuard( GetInitMutex() );
    1259           0 :     m_pDataContainer->SetBasicMode( eMode );
    1260           0 : }
    1261             : 
    1262           0 : EBasicSecurityMode SvtSecurityOptions::GetBasicMode() const
    1263             : {
    1264           0 :     MutexGuard aGuard( GetInitMutex() );
    1265           0 :     return m_pDataContainer->GetBasicMode();
    1266             : }
    1267             : 
    1268             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10