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

Generated by: LCOV version 1.10