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

Generated by: LCOV version 1.11