1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
28 #include <com/sun/star/beans/PropertyValue.hpp>
29 #include <comphelper/sequenceasvector.hxx>
30 #include <tools/urlobj.hxx>
32 #include <unotools/pathoptions.hxx>
34 #include "itemholder1.hxx"
38 using namespace ::utl
;
39 using namespace ::rtl
;
40 using namespace ::osl
;
41 using namespace ::com::sun::star::uno
;
43 #define ROOTNODE_SECURITY OUString("Office.Common/Security/Scripting")
44 #define DEFAULT_SECUREURL Sequence< OUString >()
45 #define DEFAULT_TRUSTEDAUTHORS Sequence< SvtSecurityOptions::Certificate >()
47 // xmlsec05 deprecated
48 #define DEFAULT_STAROFFICEBASIC eALWAYS_EXECUTE
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"
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
73 #define PROPERTYHANDLE_SECUREURL 0
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
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
94 #define PROPERTYCOUNT 16
95 #define PROPERTYHANDLE_INVALID -1
97 #define CFG_READONLY_DEFAULT false
99 // private declarations!
101 class SvtSecurityOptions_Impl
: public ConfigItem
108 // constructor / destructor
110 SvtSecurityOptions_Impl();
111 virtual ~SvtSecurityOptions_Impl();
113 // overloaded methods of baseclass
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
121 @seealso baseclass ConfigItem
123 @param "seqPropertyNames" is the list of properties which should be updated.
124 *//*-*****************************************************************************************************/
126 virtual void Notify( const Sequence
< OUString
>& seqPropertyNames
) SAL_OVERRIDE
;
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.
133 @seealso baseclass ConfigItem
134 *//*-*****************************************************************************************************/
136 virtual void Commit() SAL_OVERRIDE
;
140 bool IsReadOnly ( SvtSecurityOptions::EOption eOption
) const;
142 Sequence
< OUString
> GetSecureURLs ( ) const;
143 void SetSecureURLs ( const Sequence
< OUString
>& seqURLList
);
144 inline sal_Int32
GetMacroSecurityLevel ( ) const;
145 void SetMacroSecurityLevel ( sal_Int32 _nLevel
);
147 inline bool IsMacroDisabled ( ) const;
149 Sequence
< SvtSecurityOptions::Certificate
> GetTrustedAuthors ( ) const;
150 void SetTrustedAuthors ( const Sequence
< SvtSecurityOptions::Certificate
>& rAuthors
);
152 bool IsOptionSet ( SvtSecurityOptions::EOption eOption
) const;
153 bool SetOption ( SvtSecurityOptions::EOption eOption
, bool bValue
);
154 bool IsOptionEnabled ( SvtSecurityOptions::EOption eOption
) const;
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 *//*-*****************************************************************************************************/
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
);
168 static Sequence
< OUString
> GetPropertyNames();
170 Sequence
< OUString
> m_seqSecureURLs
;
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
;
183 bool m_bROSecureURLs
;
184 bool m_bROSaveOrSend
;
188 bool m_bRORemoveInfo
;
189 bool m_bRORecommendPwd
;
190 bool m_bROCtrlClickHyperlink
;
191 bool m_bROBlockUntrustedRefererLinks
;
193 bool m_bROTrustedAuthors
;
194 bool m_bRODisableMacros
;
196 // xmlsec05 deprecated
197 EBasicSecurityMode m_eBasicMode
;
198 bool m_bExecutePlugins
;
200 bool m_bConfirmation
;
202 bool m_bROConfirmation
;
204 bool m_bROExecutePlugins
;
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
);
219 SvtSecurityOptions_Impl::SvtSecurityOptions_Impl()
220 :ConfigItem ( ROOTNODE_SECURITY
)
221 ,m_seqSecureURLs ( DEFAULT_SECUREURL
)
222 ,m_bSaveOrSend ( 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
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 , m_bROBasicMode ( CFG_READONLY_DEFAULT
)
255 // xmlsec05 deprecated
258 Sequence
< OUString
> seqNames
= GetPropertyNames ( );
259 Sequence
< Any
> seqValues
= GetProperties ( seqNames
);
260 Sequence
< sal_Bool
> seqRO
= GetReadOnlyStates ( seqNames
);
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" );
267 // Copy values from list in right order to our internal member.
268 sal_Int32 nPropertyCount
= seqValues
.getLength();
269 for( sal_Int32 nProperty
= 0; nProperty
< nPropertyCount
; ++nProperty
)
270 SetProperty( nProperty
, seqValues
[ nProperty
], seqRO
[ nProperty
] );
274 // Enable notification mechanism of our baseclass.
275 // We need it to get information about changes outside these class on our used configuration keys!*/
277 EnableNotification( seqNames
);
282 SvtSecurityOptions_Impl::~SvtSecurityOptions_Impl()
288 void SvtSecurityOptions_Impl::SetProperty( sal_Int32 nProperty
, const Any
& rValue
, bool bRO
)
292 case PROPERTYHANDLE_SECUREURL
:
294 m_seqSecureURLs
.realloc( 0 );
295 rValue
>>= m_seqSecureURLs
;
297 sal_uInt32 nCount
= m_seqSecureURLs
.getLength();
298 for( sal_uInt32 nItem
= 0; nItem
< nCount
; ++nItem
)
299 m_seqSecureURLs
[ nItem
] = aOpt
.SubstituteVariable( m_seqSecureURLs
[ nItem
] );
300 m_bROSecureURLs
= bRO
;
304 case PROPERTYHANDLE_DOCWARN_SAVEORSEND
:
306 rValue
>>= m_bSaveOrSend
;
307 m_bROSaveOrSend
= bRO
;
311 case PROPERTYHANDLE_DOCWARN_SIGNING
:
313 rValue
>>= m_bSigning
;
318 case PROPERTYHANDLE_DOCWARN_PRINT
:
325 case PROPERTYHANDLE_DOCWARN_CREATEPDF
:
327 rValue
>>= m_bCreatePDF
;
328 m_bROCreatePDF
= bRO
;
332 case PROPERTYHANDLE_DOCWARN_REMOVEPERSONALINFO
:
334 rValue
>>= m_bRemoveInfo
;
335 m_bRORemoveInfo
= bRO
;
339 case PROPERTYHANDLE_DOCWARN_RECOMMENDPASSWORD
:
341 rValue
>>= m_bRecommendPwd
;
342 m_bRORecommendPwd
= bRO
;
346 case PROPERTYHANDLE_CTRLCLICK_HYPERLINK
:
348 rValue
>>= m_bCtrlClickHyperlink
;
349 m_bROCtrlClickHyperlink
= bRO
;
353 case PROPERTYHANDLE_BLOCKUNTRUSTEDREFERERLINKS
:
355 rValue
>>= m_bBlockUntrustedRefererLinks
;
356 m_bROBlockUntrustedRefererLinks
= bRO
;
360 case PROPERTYHANDLE_MACRO_SECLEVEL
:
362 rValue
>>= m_nSecLevel
;
367 case PROPERTYHANDLE_MACRO_TRUSTEDAUTHORS
:
369 // don't care about value here...
370 m_bROTrustedAuthors
= bRO
;
374 case PROPERTYHANDLE_MACRO_DISABLE
:
376 rValue
>>= m_bDisableMacros
;
377 m_bRODisableMacros
= bRO
;
381 // xmlsec05 deprecated
382 case PROPERTYHANDLE_STAROFFICEBASIC
:
386 m_eBasicMode
= (EBasicSecurityMode
)nMode
;
387 m_bROBasicMode
= bRO
;
390 case PROPERTYHANDLE_EXECUTEPLUGINS
:
392 rValue
>>= m_bExecutePlugins
;
393 m_bROExecutePlugins
= bRO
;
396 case PROPERTYHANDLE_WARNINGENABLED
:
398 rValue
>>= m_bWarning
;
402 case PROPERTYHANDLE_CONFIRMATIONENABLED
:
404 rValue
>>= m_bConfirmation
;
405 m_bROConfirmation
= bRO
;
408 // xmlsec05 deprecated
410 #if OSL_DEBUG_LEVEL > 1
412 DBG_ASSERT( false, "SvtSecurityOptions_Impl::SetProperty()\nUnknown property!\n" );
417 void SvtSecurityOptions_Impl::LoadAuthors( void )
419 m_seqTrustedAuthors
.realloc( 0 ); // first clear
420 Sequence
< OUString
> lAuthors
= GetNodeNames( PROPERTYNAME_MACRO_TRUSTEDAUTHORS
);
421 sal_Int32 c1
= lAuthors
.getLength();
424 sal_Int32 c2
= c1
* 3; // 3 Properties inside Struct TrustedAuthor
425 Sequence
< OUString
> lAllAuthors( c2
);
429 OUString
aSep( "/" );
430 for( i1
= 0, i2
= 0; i1
< c1
; ++i1
)
432 lAllAuthors
[ i2
] = PROPERTYNAME_MACRO_TRUSTEDAUTHORS
+ aSep
+ lAuthors
[ i1
] + aSep
+ PROPERTYNAME_TRUSTEDAUTHOR_SUBJECTNAME
;
434 lAllAuthors
[ i2
] = PROPERTYNAME_MACRO_TRUSTEDAUTHORS
+ aSep
+ lAuthors
[ i1
] + aSep
+ PROPERTYNAME_TRUSTEDAUTHOR_SERIALNUMBER
;
436 lAllAuthors
[ i2
] = PROPERTYNAME_MACRO_TRUSTEDAUTHORS
+ aSep
+ lAuthors
[ i1
] + aSep
+ PROPERTYNAME_TRUSTEDAUTHOR_RAWDATA
;
440 Sequence
< Any
> lValues
= GetProperties( lAllAuthors
);
441 if( lValues
.getLength() == c2
)
443 comphelper::SequenceAsVector
< SvtSecurityOptions::Certificate
> v
;
444 SvtSecurityOptions::Certificate
aCert( 3 );
445 for( i1
= 0, i2
= 0; i1
< c1
; ++i1
)
447 lValues
[ i2
] >>= aCert
[ 0 ];
449 lValues
[ i2
] >>= aCert
[ 1 ];
451 lValues
[ i2
] >>= aCert
[ 2 ];
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 if( !aCert
[ 2 ].isEmpty() )
459 v
.push_back( aCert
);
462 m_seqTrustedAuthors
= v
.getAsConstList();
467 sal_Int32
SvtSecurityOptions_Impl::GetHandle( const OUString
& rName
)
471 if( rName
== PROPERTYNAME_SECUREURL
)
472 nHandle
= PROPERTYHANDLE_SECUREURL
;
473 else if( rName
== PROPERTYNAME_DOCWARN_SAVEORSEND
)
474 nHandle
= PROPERTYHANDLE_DOCWARN_SAVEORSEND
;
475 else if( rName
== PROPERTYNAME_DOCWARN_SIGNING
)
476 nHandle
= PROPERTYHANDLE_DOCWARN_SIGNING
;
477 else if( rName
== PROPERTYNAME_DOCWARN_PRINT
)
478 nHandle
= PROPERTYHANDLE_DOCWARN_PRINT
;
479 else if( rName
== PROPERTYNAME_DOCWARN_CREATEPDF
)
480 nHandle
= PROPERTYHANDLE_DOCWARN_CREATEPDF
;
481 else if( rName
== PROPERTYNAME_DOCWARN_REMOVEPERSONALINFO
)
482 nHandle
= PROPERTYHANDLE_DOCWARN_REMOVEPERSONALINFO
;
483 else if( rName
== PROPERTYNAME_DOCWARN_RECOMMENDPASSWORD
)
484 nHandle
= PROPERTYHANDLE_DOCWARN_RECOMMENDPASSWORD
;
485 else if( rName
== PROPERTYNAME_CTRLCLICK_HYPERLINK
)
486 nHandle
= PROPERTYHANDLE_CTRLCLICK_HYPERLINK
;
487 else if( rName
== PROPERTYNAME_BLOCKUNTRUSTEDREFERERLINKS
)
488 nHandle
= PROPERTYHANDLE_BLOCKUNTRUSTEDREFERERLINKS
;
489 else if( rName
== PROPERTYNAME_MACRO_SECLEVEL
)
490 nHandle
= PROPERTYHANDLE_MACRO_SECLEVEL
;
491 else if( rName
== PROPERTYNAME_MACRO_TRUSTEDAUTHORS
)
492 nHandle
= PROPERTYHANDLE_MACRO_TRUSTEDAUTHORS
;
493 else if( rName
== PROPERTYNAME_MACRO_DISABLE
)
494 nHandle
= PROPERTYHANDLE_MACRO_DISABLE
;
496 // xmlsec05 deprecated
497 else if( rName
== PROPERTYNAME_STAROFFICEBASIC
)
498 nHandle
= PROPERTYHANDLE_STAROFFICEBASIC
;
499 else if( rName
== PROPERTYNAME_EXECUTEPLUGINS
)
500 nHandle
= PROPERTYHANDLE_EXECUTEPLUGINS
;
501 else if( rName
== PROPERTYNAME_WARNINGENABLED
)
502 nHandle
= PROPERTYHANDLE_WARNINGENABLED
;
503 else if( rName
== PROPERTYNAME_CONFIRMATIONENABLED
)
504 nHandle
= PROPERTYHANDLE_CONFIRMATIONENABLED
;
505 // xmlsec05 deprecated
508 nHandle
= PROPERTYHANDLE_INVALID
;
513 bool SvtSecurityOptions_Impl::GetOption( SvtSecurityOptions::EOption eOption
, bool*& rpValue
, bool*& rpRO
)
517 case SvtSecurityOptions::E_DOCWARN_SAVEORSEND
:
518 rpValue
= &m_bSaveOrSend
;
519 rpRO
= &m_bROSaveOrSend
;
521 case SvtSecurityOptions::E_DOCWARN_SIGNING
:
522 rpValue
= &m_bSigning
;
523 rpRO
= &m_bROSigning
;
525 case SvtSecurityOptions::E_DOCWARN_PRINT
:
529 case SvtSecurityOptions::E_DOCWARN_CREATEPDF
:
530 rpValue
= &m_bCreatePDF
;
531 rpRO
= &m_bROCreatePDF
;
533 case SvtSecurityOptions::E_DOCWARN_REMOVEPERSONALINFO
:
534 rpValue
= &m_bRemoveInfo
;
535 rpRO
= &m_bRORemoveInfo
;
537 case SvtSecurityOptions::E_DOCWARN_RECOMMENDPASSWORD
:
538 rpValue
= &m_bRecommendPwd
;
539 rpRO
= &m_bRORecommendPwd
;
541 case SvtSecurityOptions::E_CTRLCLICK_HYPERLINK
:
542 rpValue
= &m_bCtrlClickHyperlink
;
543 rpRO
= &m_bROCtrlClickHyperlink
;
545 case SvtSecurityOptions::E_BLOCKUNTRUSTEDREFERERLINKS
:
546 rpValue
= &m_bBlockUntrustedRefererLinks
;
547 rpRO
= &m_bROBlockUntrustedRefererLinks
;
555 return rpValue
!= NULL
;
558 void SvtSecurityOptions_Impl::Notify( const Sequence
< OUString
>& seqPropertyNames
)
560 // Use given list of updated properties to get his values from configuration directly!
561 Sequence
< Any
> seqValues
= GetProperties( seqPropertyNames
);
562 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 sal_Int32 nCount
= seqPropertyNames
.getLength();
568 for( sal_Int32 nProperty
= 0; nProperty
< nCount
; ++nProperty
)
569 SetProperty( GetHandle( seqPropertyNames
[ nProperty
] ), seqValues
[ nProperty
], seqRO
[ nProperty
] );
571 // read set of trusted authors separately
575 void SvtSecurityOptions_Impl::Commit()
577 // Get names of supported properties, create a list for values and copy current values to it.
578 Sequence
< OUString
> lOrgNames
= GetPropertyNames();
579 sal_Int32 nOrgCount
= lOrgNames
.getLength();
581 Sequence
< OUString
> lNames(nOrgCount
);
582 Sequence
< Any
> lValues(nOrgCount
);
583 sal_Int32 nRealCount
= 0;
586 ClearNodeSet( PROPERTYNAME_MACRO_TRUSTEDAUTHORS
);
588 for( sal_Int32 nProperty
= 0; nProperty
< nOrgCount
; ++nProperty
)
592 case PROPERTYHANDLE_SECUREURL
:
594 bDone
= !m_bROSecureURLs
;
597 Sequence
< OUString
> lURLs( m_seqSecureURLs
);
599 sal_Int32 nURLsCnt
= lURLs
.getLength();
600 for( sal_Int32 nItem
= 0; nItem
< nURLsCnt
; ++nItem
)
601 lURLs
[ nItem
] = aOpt
.UseVariable( lURLs
[ nItem
] );
602 lValues
[ nRealCount
] <<= lURLs
;
607 case PROPERTYHANDLE_DOCWARN_SAVEORSEND
:
609 bDone
= !m_bROSaveOrSend
;
611 lValues
[ nRealCount
] <<= m_bSaveOrSend
;
615 case PROPERTYHANDLE_DOCWARN_SIGNING
:
617 bDone
= !m_bROSigning
;
619 lValues
[ nRealCount
] <<= m_bSigning
;
623 case PROPERTYHANDLE_DOCWARN_PRINT
:
627 lValues
[ nRealCount
] <<= m_bPrint
;
631 case PROPERTYHANDLE_DOCWARN_CREATEPDF
:
633 bDone
= !m_bROCreatePDF
;
635 lValues
[ nRealCount
] <<= m_bCreatePDF
;
639 case PROPERTYHANDLE_DOCWARN_REMOVEPERSONALINFO
:
641 bDone
= !m_bRORemoveInfo
;
643 lValues
[ nRealCount
] <<= m_bRemoveInfo
;
647 case PROPERTYHANDLE_DOCWARN_RECOMMENDPASSWORD
:
649 bDone
= !m_bRORecommendPwd
;
651 lValues
[ nRealCount
] <<= m_bRecommendPwd
;
655 case PROPERTYHANDLE_CTRLCLICK_HYPERLINK
:
657 bDone
= !m_bROCtrlClickHyperlink
;
659 lValues
[ nRealCount
] <<= m_bCtrlClickHyperlink
;
663 case PROPERTYHANDLE_BLOCKUNTRUSTEDREFERERLINKS
:
665 bDone
= !m_bROBlockUntrustedRefererLinks
;
667 lValues
[ nRealCount
] <<= m_bBlockUntrustedRefererLinks
;
671 case PROPERTYHANDLE_MACRO_SECLEVEL
:
673 bDone
= !m_bROSecLevel
;
675 lValues
[ nRealCount
] <<= m_nSecLevel
;
679 case PROPERTYHANDLE_MACRO_TRUSTEDAUTHORS
:
681 bDone
= !m_bROTrustedAuthors
;
684 sal_Int32 nCnt
= m_seqTrustedAuthors
.getLength();
687 for( sal_Int32 i
= 0; i
< nCnt
; ++i
)
690 PROPERTYNAME_MACRO_TRUSTEDAUTHORS
"/a"
691 + OUString::number(i
) + "/");
692 Sequence
< com::sun::star::beans::PropertyValue
> lPropertyValues( 3 );
693 lPropertyValues
[ 0 ].Name
= aPrefix
+ PROPERTYNAME_TRUSTEDAUTHOR_SUBJECTNAME
;
694 lPropertyValues
[ 0 ].Value
<<= m_seqTrustedAuthors
[ i
][0];
695 lPropertyValues
[ 1 ].Name
= aPrefix
+ PROPERTYNAME_TRUSTEDAUTHOR_SERIALNUMBER
;
696 lPropertyValues
[ 1 ].Value
<<= m_seqTrustedAuthors
[ i
][1];
697 lPropertyValues
[ 2 ].Name
= aPrefix
+ PROPERTYNAME_TRUSTEDAUTHOR_RAWDATA
;
698 lPropertyValues
[ 2 ].Value
<<= m_seqTrustedAuthors
[ i
][2];
700 SetSetProperties( PROPERTYNAME_MACRO_TRUSTEDAUTHORS
, lPropertyValues
);
703 bDone
= false; // because we save in loop above!
711 case PROPERTYHANDLE_MACRO_DISABLE
:
713 bDone
= !m_bRODisableMacros
;
715 lValues
[ nRealCount
] <<= m_bDisableMacros
;
719 // xmlsec05 deprecated
720 case PROPERTYHANDLE_STAROFFICEBASIC
:
722 bDone
= !m_bROBasicMode
;
724 lValues
[ nRealCount
] <<= (sal_Int32
)m_eBasicMode
;
727 case PROPERTYHANDLE_EXECUTEPLUGINS
:
729 bDone
= !m_bROExecutePlugins
;
731 lValues
[ nRealCount
] <<= m_bExecutePlugins
;
734 case PROPERTYHANDLE_WARNINGENABLED
:
736 bDone
= !m_bROWarning
;
738 lValues
[ nRealCount
] <<= m_bWarning
;
741 case PROPERTYHANDLE_CONFIRMATIONENABLED
:
743 bDone
= !m_bROConfirmation
;
745 lValues
[ nRealCount
] <<= m_bConfirmation
;
748 // xmlsec05 deprecated
756 lNames
[ nRealCount
] = lOrgNames
[ nProperty
];
760 // Set properties in configuration.
761 lNames
.realloc(nRealCount
);
762 lValues
.realloc(nRealCount
);
763 PutProperties( lNames
, lValues
);
766 bool SvtSecurityOptions_Impl::IsReadOnly( SvtSecurityOptions::EOption eOption
) const
771 case SvtSecurityOptions::E_SECUREURLS
:
772 bReadonly
= m_bROSecureURLs
;
774 case SvtSecurityOptions::E_DOCWARN_SAVEORSEND
:
775 bReadonly
= m_bROSaveOrSend
;
777 case SvtSecurityOptions::E_DOCWARN_SIGNING
:
778 bReadonly
= m_bROSigning
;
780 case SvtSecurityOptions::E_DOCWARN_PRINT
:
781 bReadonly
= m_bROPrint
;
783 case SvtSecurityOptions::E_DOCWARN_CREATEPDF
:
784 bReadonly
= m_bROCreatePDF
;
786 case SvtSecurityOptions::E_DOCWARN_REMOVEPERSONALINFO
:
787 bReadonly
= m_bRORemoveInfo
;
789 case SvtSecurityOptions::E_DOCWARN_RECOMMENDPASSWORD
:
790 bReadonly
= m_bRORecommendPwd
;
792 case SvtSecurityOptions::E_MACRO_SECLEVEL
:
793 bReadonly
= m_bROSecLevel
;
795 case SvtSecurityOptions::E_MACRO_TRUSTEDAUTHORS
:
796 bReadonly
= m_bROTrustedAuthors
;
798 case SvtSecurityOptions::E_MACRO_DISABLE
:
799 bReadonly
= m_bRODisableMacros
;
801 case SvtSecurityOptions::E_CTRLCLICK_HYPERLINK
:
802 bReadonly
= m_bROCtrlClickHyperlink
;
804 case SvtSecurityOptions::E_BLOCKUNTRUSTEDREFERERLINKS
:
805 bReadonly
= m_bROBlockUntrustedRefererLinks
;
808 // xmlsec05 deprecated
809 case SvtSecurityOptions::E_BASICMODE
:
810 bReadonly
= m_bROBasicMode
;
812 case SvtSecurityOptions::E_EXECUTEPLUGINS
:
813 bReadonly
= m_bROExecutePlugins
;
815 case SvtSecurityOptions::E_WARNING
:
816 bReadonly
= m_bROWarning
;
818 case SvtSecurityOptions::E_CONFIRMATION
:
819 bReadonly
= m_bROConfirmation
;
821 // xmlsec05 deprecated
830 Sequence
< OUString
> SvtSecurityOptions_Impl::GetSecureURLs() const
832 return m_seqSecureURLs
;
835 void SvtSecurityOptions_Impl::SetSecureURLs( const Sequence
< OUString
>& seqURLList
)
837 DBG_ASSERT(!m_bROSecureURLs
, "SvtSecurityOptions_Impl::SetSecureURLs()\nYou tried to write on a readonly value!\n");
838 if (!m_bROSecureURLs
&& m_seqSecureURLs
!=seqURLList
)
840 m_seqSecureURLs
= seqURLList
;
845 inline sal_Int32
SvtSecurityOptions_Impl::GetMacroSecurityLevel() const
850 inline bool SvtSecurityOptions_Impl::IsMacroDisabled() const
852 return m_bDisableMacros
;
855 void SvtSecurityOptions_Impl::SetMacroSecurityLevel( sal_Int32 _nLevel
)
859 if( _nLevel
> 3 || _nLevel
< 0 )
862 if( m_nSecLevel
!= _nLevel
)
864 m_nSecLevel
= _nLevel
;
870 Sequence
< SvtSecurityOptions::Certificate
> SvtSecurityOptions_Impl::GetTrustedAuthors() const
872 return m_seqTrustedAuthors
;
875 void SvtSecurityOptions_Impl::SetTrustedAuthors( const Sequence
< SvtSecurityOptions::Certificate
>& rAuthors
)
877 DBG_ASSERT(!m_bROTrustedAuthors
, "SvtSecurityOptions_Impl::SetTrustedAuthors()\nYou tried to write on a readonly value!\n");
878 if( !m_bROTrustedAuthors
&& rAuthors
!= m_seqTrustedAuthors
)
880 m_seqTrustedAuthors
= rAuthors
;
885 bool SvtSecurityOptions_Impl::IsOptionSet( SvtSecurityOptions::EOption eOption
) const
891 if( ( const_cast< SvtSecurityOptions_Impl
* >( this ) )->GetOption( eOption
, pValue
, pRO
) )
897 bool SvtSecurityOptions_Impl::SetOption( SvtSecurityOptions::EOption eOption
, bool bValue
)
903 if( GetOption( eOption
, pValue
, pRO
) )
908 if( *pValue
!= bValue
)
919 bool SvtSecurityOptions_Impl::IsOptionEnabled( SvtSecurityOptions::EOption eOption
) const
925 if( ( const_cast< SvtSecurityOptions_Impl
* >( this ) )->GetOption( eOption
, pValue
, pRO
) )
931 Sequence
< OUString
> SvtSecurityOptions_Impl::GetPropertyNames()
933 // Build static list of configuration key names.
934 const OUString pProperties
[] =
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
)
953 // Initialize return sequence with these list ...
954 const Sequence
< OUString
> seqPropertyNames( pProperties
, PROPERTYCOUNT
);
955 // ... and return it.
956 return seqPropertyNames
;
959 // initialize static member
960 // DON'T DO IT IN YOUR HEADER!
961 // see definition for further information
963 SvtSecurityOptions_Impl
* SvtSecurityOptions::m_pDataContainer
= NULL
;
964 sal_Int32
SvtSecurityOptions::m_nRefCount
= 0;
966 SvtSecurityOptions::SvtSecurityOptions()
968 // Global access, must be guarded (multithreading!).
969 MutexGuard
aGuard( GetInitMutex() );
970 // Increase our refcount ...
972 // ... and initialize our data container only if it not already exist!
973 if( m_pDataContainer
== NULL
)
975 m_pDataContainer
= new SvtSecurityOptions_Impl
;
977 ItemHolder1::holdConfigItem(E_SECURITYOPTIONS
);
981 SvtSecurityOptions::~SvtSecurityOptions()
983 // Global access, must be guarded (multithreading!)
984 MutexGuard
aGuard( GetInitMutex() );
985 // Decrease our refcount.
987 // If last instance was deleted ...
988 // we must destroy our static data container!
989 if( m_nRefCount
<= 0 )
991 delete m_pDataContainer
;
992 m_pDataContainer
= NULL
;
996 bool SvtSecurityOptions::IsReadOnly( EOption eOption
) const
998 MutexGuard
aGuard( GetInitMutex() );
999 return m_pDataContainer
->IsReadOnly(eOption
);
1002 Sequence
< OUString
> SvtSecurityOptions::GetSecureURLs() const
1004 MutexGuard
aGuard( GetInitMutex() );
1005 return m_pDataContainer
->GetSecureURLs();
1008 void SvtSecurityOptions::SetSecureURLs( const Sequence
< OUString
>& seqURLList
)
1010 MutexGuard
aGuard( GetInitMutex() );
1011 m_pDataContainer
->SetSecureURLs( seqURLList
);
1014 bool SvtSecurityOptions::isSecureMacroUri(
1015 OUString
const & uri
, OUString
const & referer
) const
1017 switch (INetURLObject(uri
).GetProtocol()) {
1018 case INET_PROT_MACRO
:
1019 if (uri
.startsWithIgnoreAsciiCase("macro:///")) {
1020 // Denotes an App-BASIC macro (see SfxMacroLoader::loadMacro), which
1021 // is considered safe:
1025 case INET_PROT_SLOT
:
1026 return referer
.equalsIgnoreAsciiCase("private:user")
1027 || isTrustedLocationUri(referer
);
1033 bool SvtSecurityOptions::isUntrustedReferer(OUString
const & referer
) const {
1034 MutexGuard
g(GetInitMutex());
1035 return m_pDataContainer
->IsOptionSet(E_BLOCKUNTRUSTEDREFERERLINKS
)
1036 && !(referer
.isEmpty() || referer
.startsWithIgnoreAsciiCase("private:")
1037 || isTrustedLocationUri(referer
));
1040 bool SvtSecurityOptions::isTrustedLocationUri(OUString
const & uri
) const {
1041 MutexGuard
g(GetInitMutex());
1042 for (sal_Int32 i
= 0; i
!= m_pDataContainer
->m_seqSecureURLs
.getLength();
1045 if (UCBContentHelper::IsSubPath(
1046 m_pDataContainer
->m_seqSecureURLs
[i
], uri
))
1054 sal_Int32
SvtSecurityOptions::GetMacroSecurityLevel() const
1056 MutexGuard
aGuard( GetInitMutex() );
1057 return m_pDataContainer
->GetMacroSecurityLevel();
1060 void SvtSecurityOptions::SetMacroSecurityLevel( sal_Int32 _nLevel
)
1062 MutexGuard
aGuard( GetInitMutex() );
1063 m_pDataContainer
->SetMacroSecurityLevel( _nLevel
);
1066 bool SvtSecurityOptions::IsMacroDisabled() const
1068 MutexGuard
aGuard( GetInitMutex() );
1069 return m_pDataContainer
->IsMacroDisabled();
1072 Sequence
< SvtSecurityOptions::Certificate
> SvtSecurityOptions::GetTrustedAuthors() const
1074 MutexGuard
aGuard( GetInitMutex() );
1075 return m_pDataContainer
->GetTrustedAuthors();
1078 void SvtSecurityOptions::SetTrustedAuthors( const Sequence
< Certificate
>& rAuthors
)
1080 MutexGuard
aGuard( GetInitMutex() );
1081 m_pDataContainer
->SetTrustedAuthors( rAuthors
);
1084 bool SvtSecurityOptions::IsOptionSet( EOption eOption
) const
1086 MutexGuard
aGuard( GetInitMutex() );
1087 return m_pDataContainer
->IsOptionSet( eOption
);
1090 bool SvtSecurityOptions::SetOption( EOption eOption
, bool bValue
)
1092 MutexGuard
aGuard( GetInitMutex() );
1093 return m_pDataContainer
->SetOption( eOption
, bValue
);
1096 bool SvtSecurityOptions::IsOptionEnabled( EOption eOption
) const
1098 MutexGuard
aGuard( GetInitMutex() );
1099 return m_pDataContainer
->IsOptionEnabled( eOption
);
1104 class theSecurityOptionsMutex
: public rtl::Static
<osl::Mutex
, theSecurityOptionsMutex
>{};
1107 Mutex
& SvtSecurityOptions::GetInitMutex()
1109 return theSecurityOptionsMutex::get();
1112 // xmlsec05 deprecated
1114 EBasicSecurityMode
SvtSecurityOptions_Impl::GetBasicMode() const
1116 return m_eBasicMode
;
1119 void SvtSecurityOptions_Impl::SetBasicMode( EBasicSecurityMode eMode
)
1121 DBG_ASSERT(!m_bROBasicMode
, "SvtSecurityOptions_Impl::SetBasicMode()\nYou tried to write on a readonly value!\n");
1122 if (!m_bROBasicMode
&& m_eBasicMode
!=eMode
)
1124 m_eBasicMode
= eMode
;
1129 bool SvtSecurityOptions_Impl::IsExecutePlugins() const
1131 return m_bExecutePlugins
;
1134 void SvtSecurityOptions_Impl::SetExecutePlugins( bool bSet
)
1136 DBG_ASSERT(!m_bROExecutePlugins
, "SvtSecurityOptions_Impl::SetExecutePlugins()\nYou tried to write on a readonly value!\n");
1137 if (!m_bROExecutePlugins
&& m_bExecutePlugins
!=bSet
)
1139 m_bExecutePlugins
= bSet
;
1144 bool SvtSecurityOptions_Impl::IsWarningEnabled() const
1149 void SvtSecurityOptions_Impl::SetWarningEnabled( bool bSet
)
1151 DBG_ASSERT(!m_bROWarning
, "SvtSecurityOptions_Impl::SetWarningEnabled()\nYou tried to write on a readonly value!\n");
1152 if (!m_bROWarning
&& m_bWarning
!=bSet
)
1159 bool SvtSecurityOptions_Impl::IsConfirmationEnabled() const
1161 return m_bConfirmation
;
1164 void SvtSecurityOptions_Impl::SetConfirmationEnabled( bool bSet
)
1166 DBG_ASSERT(!m_bROConfirmation
, "SvtSecurityOptions_Impl::SetConfirmationEnabled()\nYou tried to write on a readonly value!\n");
1167 if (!m_bROConfirmation
&& m_bConfirmation
!=bSet
)
1169 m_bConfirmation
= bSet
;
1174 bool SvtSecurityOptions::IsExecutePlugins() const
1176 MutexGuard
aGuard( GetInitMutex() );
1177 return m_pDataContainer
->IsExecutePlugins();
1180 void SvtSecurityOptions::SetExecutePlugins( bool bSet
)
1182 MutexGuard
aGuard( GetInitMutex() );
1183 m_pDataContainer
->SetExecutePlugins( bSet
);
1186 bool SvtSecurityOptions::IsWarningEnabled() const
1188 MutexGuard
aGuard( GetInitMutex() );
1189 return m_pDataContainer
->IsWarningEnabled();
1192 void SvtSecurityOptions::SetWarningEnabled( bool bSet
)
1194 MutexGuard
aGuard( GetInitMutex() );
1195 m_pDataContainer
->SetWarningEnabled( bSet
);
1198 bool SvtSecurityOptions::IsConfirmationEnabled() const
1200 MutexGuard
aGuard( GetInitMutex() );
1201 return m_pDataContainer
->IsConfirmationEnabled();
1204 void SvtSecurityOptions::SetConfirmationEnabled( bool bSet
)
1206 MutexGuard
aGuard( GetInitMutex() );
1207 m_pDataContainer
->SetConfirmationEnabled( bSet
);
1210 void SvtSecurityOptions::SetBasicMode( EBasicSecurityMode eMode
)
1212 MutexGuard
aGuard( GetInitMutex() );
1213 m_pDataContainer
->SetBasicMode( eMode
);
1216 EBasicSecurityMode
SvtSecurityOptions::GetBasicMode() const
1218 MutexGuard
aGuard( GetInitMutex() );
1219 return m_pDataContainer
->GetBasicMode();
1222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */