Bump version to 4.3-4
[LibreOffice.git] / unotools / source / config / securityoptions.cxx
blob7906ed7cc7268a02c28b18301c42f9fb1e3fdf26
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
36 // namespaces
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
104 // public methods
106 public:
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
119 internal values.
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;
138 // public interface
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;
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;
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;
196 // xmlsec05 deprecated
197 EBasicSecurityMode m_eBasicMode;
198 bool m_bExecutePlugins;
199 bool m_bWarning;
200 bool m_bConfirmation;
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 );
217 // constructor
219 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
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 ] );
272 LoadAuthors();
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 );
280 // destructor
282 SvtSecurityOptions_Impl::~SvtSecurityOptions_Impl()
284 if( IsModified() )
285 Commit();
288 void SvtSecurityOptions_Impl::SetProperty( sal_Int32 nProperty, const Any& rValue, bool bRO )
290 switch( nProperty )
292 case PROPERTYHANDLE_SECUREURL:
294 m_seqSecureURLs.realloc( 0 );
295 rValue >>= m_seqSecureURLs;
296 SvtPathOptions aOpt;
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;
302 break;
304 case PROPERTYHANDLE_DOCWARN_SAVEORSEND:
306 rValue >>= m_bSaveOrSend;
307 m_bROSaveOrSend = bRO;
309 break;
311 case PROPERTYHANDLE_DOCWARN_SIGNING:
313 rValue >>= m_bSigning;
314 m_bROSigning = bRO;
316 break;
318 case PROPERTYHANDLE_DOCWARN_PRINT:
320 rValue >>= m_bPrint;
321 m_bROPrint = bRO;
323 break;
325 case PROPERTYHANDLE_DOCWARN_CREATEPDF:
327 rValue >>= m_bCreatePDF;
328 m_bROCreatePDF = bRO;
330 break;
332 case PROPERTYHANDLE_DOCWARN_REMOVEPERSONALINFO:
334 rValue >>= m_bRemoveInfo;
335 m_bRORemoveInfo = bRO;
337 break;
339 case PROPERTYHANDLE_DOCWARN_RECOMMENDPASSWORD:
341 rValue >>= m_bRecommendPwd;
342 m_bRORecommendPwd = bRO;
344 break;
346 case PROPERTYHANDLE_CTRLCLICK_HYPERLINK:
348 rValue >>= m_bCtrlClickHyperlink;
349 m_bROCtrlClickHyperlink = bRO;
351 break;
353 case PROPERTYHANDLE_BLOCKUNTRUSTEDREFERERLINKS:
355 rValue >>= m_bBlockUntrustedRefererLinks;
356 m_bROBlockUntrustedRefererLinks = bRO;
358 break;
360 case PROPERTYHANDLE_MACRO_SECLEVEL:
362 rValue >>= m_nSecLevel;
363 m_bROSecLevel = bRO;
365 break;
367 case PROPERTYHANDLE_MACRO_TRUSTEDAUTHORS:
369 // don't care about value here...
370 m_bROTrustedAuthors = bRO;
372 break;
374 case PROPERTYHANDLE_MACRO_DISABLE:
376 rValue >>= m_bDisableMacros;
377 m_bRODisableMacros = bRO;
379 break;
381 // xmlsec05 deprecated
382 case PROPERTYHANDLE_STAROFFICEBASIC:
384 sal_Int32 nMode = 0;
385 rValue >>= nMode;
386 m_eBasicMode = (EBasicSecurityMode)nMode;
387 m_bROBasicMode = bRO;
389 break;
390 case PROPERTYHANDLE_EXECUTEPLUGINS:
392 rValue >>= m_bExecutePlugins;
393 m_bROExecutePlugins = bRO;
395 break;
396 case PROPERTYHANDLE_WARNINGENABLED:
398 rValue >>= m_bWarning;
399 m_bROWarning = bRO;
401 break;
402 case PROPERTYHANDLE_CONFIRMATIONENABLED:
404 rValue >>= m_bConfirmation;
405 m_bROConfirmation = bRO;
407 break;
408 // xmlsec05 deprecated
410 #if OSL_DEBUG_LEVEL > 1
411 default:
412 DBG_ASSERT( false, "SvtSecurityOptions_Impl::SetProperty()\nUnknown property!\n" );
413 #endif
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();
422 if( c1 )
424 sal_Int32 c2 = c1 * 3; // 3 Properties inside Struct TrustedAuthor
425 Sequence< OUString > lAllAuthors( c2 );
427 sal_Int32 i1;
428 sal_Int32 i2;
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;
433 ++i2;
434 lAllAuthors[ i2 ] = PROPERTYNAME_MACRO_TRUSTEDAUTHORS + aSep + lAuthors[ i1 ] + aSep + PROPERTYNAME_TRUSTEDAUTHOR_SERIALNUMBER;
435 ++i2;
436 lAllAuthors[ i2 ] = PROPERTYNAME_MACRO_TRUSTEDAUTHORS + aSep + lAuthors[ i1 ] + aSep + PROPERTYNAME_TRUSTEDAUTHOR_RAWDATA;
437 ++i2;
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 ];
448 ++i2;
449 lValues[ i2 ] >>= aCert[ 1 ];
450 ++i2;
451 lValues[ i2 ] >>= aCert[ 2 ];
452 ++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 if( !aCert[ 2 ].isEmpty() )
459 v.push_back( aCert );
462 m_seqTrustedAuthors = v.getAsConstList();
467 sal_Int32 SvtSecurityOptions_Impl::GetHandle( const OUString& rName )
469 sal_Int32 nHandle;
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
507 else
508 nHandle = PROPERTYHANDLE_INVALID;
510 return nHandle;
513 bool SvtSecurityOptions_Impl::GetOption( SvtSecurityOptions::EOption eOption, bool*& rpValue, bool*& rpRO )
515 switch( eOption )
517 case SvtSecurityOptions::E_DOCWARN_SAVEORSEND:
518 rpValue = &m_bSaveOrSend;
519 rpRO = &m_bROSaveOrSend;
520 break;
521 case SvtSecurityOptions::E_DOCWARN_SIGNING:
522 rpValue = &m_bSigning;
523 rpRO = &m_bROSigning;
524 break;
525 case SvtSecurityOptions::E_DOCWARN_PRINT:
526 rpValue = &m_bPrint;
527 rpRO = &m_bROPrint;
528 break;
529 case SvtSecurityOptions::E_DOCWARN_CREATEPDF:
530 rpValue = &m_bCreatePDF;
531 rpRO = &m_bROCreatePDF;
532 break;
533 case SvtSecurityOptions::E_DOCWARN_REMOVEPERSONALINFO:
534 rpValue = &m_bRemoveInfo;
535 rpRO = &m_bRORemoveInfo;
536 break;
537 case SvtSecurityOptions::E_DOCWARN_RECOMMENDPASSWORD:
538 rpValue = &m_bRecommendPwd;
539 rpRO = &m_bRORecommendPwd;
540 break;
541 case SvtSecurityOptions::E_CTRLCLICK_HYPERLINK:
542 rpValue = &m_bCtrlClickHyperlink;
543 rpRO = &m_bROCtrlClickHyperlink;
544 break;
545 case SvtSecurityOptions::E_BLOCKUNTRUSTEDREFERERLINKS:
546 rpValue = &m_bBlockUntrustedRefererLinks;
547 rpRO = &m_bROBlockUntrustedRefererLinks;
548 break;
549 default:
550 rpValue = NULL;
551 rpRO = NULL;
552 break;
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
572 LoadAuthors();
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;
584 bool bDone;
586 ClearNodeSet( PROPERTYNAME_MACRO_TRUSTEDAUTHORS );
588 for( sal_Int32 nProperty = 0; nProperty < nOrgCount; ++nProperty )
590 switch( nProperty )
592 case PROPERTYHANDLE_SECUREURL:
594 bDone = !m_bROSecureURLs;
595 if( bDone )
597 Sequence< OUString > lURLs( m_seqSecureURLs );
598 SvtPathOptions aOpt;
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;
605 break;
607 case PROPERTYHANDLE_DOCWARN_SAVEORSEND:
609 bDone = !m_bROSaveOrSend;
610 if( bDone )
611 lValues[ nRealCount ] <<= m_bSaveOrSend;
613 break;
615 case PROPERTYHANDLE_DOCWARN_SIGNING:
617 bDone = !m_bROSigning;
618 if( bDone )
619 lValues[ nRealCount ] <<= m_bSigning;
621 break;
623 case PROPERTYHANDLE_DOCWARN_PRINT:
625 bDone = !m_bROPrint;
626 if( bDone )
627 lValues[ nRealCount ] <<= m_bPrint;
629 break;
631 case PROPERTYHANDLE_DOCWARN_CREATEPDF:
633 bDone = !m_bROCreatePDF;
634 if( bDone )
635 lValues[ nRealCount ] <<= m_bCreatePDF;
637 break;
639 case PROPERTYHANDLE_DOCWARN_REMOVEPERSONALINFO:
641 bDone = !m_bRORemoveInfo;
642 if( bDone )
643 lValues[ nRealCount ] <<= m_bRemoveInfo;
645 break;
647 case PROPERTYHANDLE_DOCWARN_RECOMMENDPASSWORD:
649 bDone = !m_bRORecommendPwd;
650 if( bDone )
651 lValues[ nRealCount ] <<= m_bRecommendPwd;
653 break;
655 case PROPERTYHANDLE_CTRLCLICK_HYPERLINK:
657 bDone = !m_bROCtrlClickHyperlink;
658 if( bDone )
659 lValues[ nRealCount ] <<= m_bCtrlClickHyperlink;
661 break;
663 case PROPERTYHANDLE_BLOCKUNTRUSTEDREFERERLINKS:
665 bDone = !m_bROBlockUntrustedRefererLinks;
666 if( bDone )
667 lValues[ nRealCount ] <<= m_bBlockUntrustedRefererLinks;
669 break;
671 case PROPERTYHANDLE_MACRO_SECLEVEL:
673 bDone = !m_bROSecLevel;
674 if( bDone )
675 lValues[ nRealCount ] <<= m_nSecLevel;
677 break;
679 case PROPERTYHANDLE_MACRO_TRUSTEDAUTHORS:
681 bDone = !m_bROTrustedAuthors;
682 if( bDone )
684 sal_Int32 nCnt = m_seqTrustedAuthors.getLength();
685 if( nCnt )
687 for( sal_Int32 i = 0; i < nCnt; ++i )
689 OUString aPrefix(
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!
705 else
706 bDone = false;
709 break;
711 case PROPERTYHANDLE_MACRO_DISABLE:
713 bDone = !m_bRODisableMacros;
714 if( bDone )
715 lValues[ nRealCount ] <<= m_bDisableMacros;
717 break;
719 // xmlsec05 deprecated
720 case PROPERTYHANDLE_STAROFFICEBASIC:
722 bDone = !m_bROBasicMode;
723 if( bDone )
724 lValues[ nRealCount ] <<= (sal_Int32)m_eBasicMode;
726 break;
727 case PROPERTYHANDLE_EXECUTEPLUGINS:
729 bDone = !m_bROExecutePlugins;
730 if( bDone )
731 lValues[ nRealCount ] <<= m_bExecutePlugins;
733 break;
734 case PROPERTYHANDLE_WARNINGENABLED:
736 bDone = !m_bROWarning;
737 if( bDone )
738 lValues[ nRealCount ] <<= m_bWarning;
740 break;
741 case PROPERTYHANDLE_CONFIRMATIONENABLED:
743 bDone = !m_bROConfirmation;
744 if( bDone )
745 lValues[ nRealCount ] <<= m_bConfirmation;
747 break;
748 // xmlsec05 deprecated
750 default:
751 bDone = false;
754 if( bDone )
756 lNames[ nRealCount ] = lOrgNames[ nProperty ];
757 ++nRealCount;
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
768 bool bReadonly;
769 switch(eOption)
771 case SvtSecurityOptions::E_SECUREURLS :
772 bReadonly = m_bROSecureURLs;
773 break;
774 case SvtSecurityOptions::E_DOCWARN_SAVEORSEND:
775 bReadonly = m_bROSaveOrSend;
776 break;
777 case SvtSecurityOptions::E_DOCWARN_SIGNING:
778 bReadonly = m_bROSigning;
779 break;
780 case SvtSecurityOptions::E_DOCWARN_PRINT:
781 bReadonly = m_bROPrint;
782 break;
783 case SvtSecurityOptions::E_DOCWARN_CREATEPDF:
784 bReadonly = m_bROCreatePDF;
785 break;
786 case SvtSecurityOptions::E_DOCWARN_REMOVEPERSONALINFO:
787 bReadonly = m_bRORemoveInfo;
788 break;
789 case SvtSecurityOptions::E_DOCWARN_RECOMMENDPASSWORD:
790 bReadonly = m_bRORecommendPwd;
791 break;
792 case SvtSecurityOptions::E_MACRO_SECLEVEL:
793 bReadonly = m_bROSecLevel;
794 break;
795 case SvtSecurityOptions::E_MACRO_TRUSTEDAUTHORS:
796 bReadonly = m_bROTrustedAuthors;
797 break;
798 case SvtSecurityOptions::E_MACRO_DISABLE:
799 bReadonly = m_bRODisableMacros;
800 break;
801 case SvtSecurityOptions::E_CTRLCLICK_HYPERLINK:
802 bReadonly = m_bROCtrlClickHyperlink;
803 break;
804 case SvtSecurityOptions::E_BLOCKUNTRUSTEDREFERERLINKS:
805 bReadonly = m_bROBlockUntrustedRefererLinks;
806 break;
808 // xmlsec05 deprecated
809 case SvtSecurityOptions::E_BASICMODE:
810 bReadonly = m_bROBasicMode;
811 break;
812 case SvtSecurityOptions::E_EXECUTEPLUGINS:
813 bReadonly = m_bROExecutePlugins;
814 break;
815 case SvtSecurityOptions::E_WARNING:
816 bReadonly = m_bROWarning;
817 break;
818 case SvtSecurityOptions::E_CONFIRMATION:
819 bReadonly = m_bROConfirmation;
820 break;
821 // xmlsec05 deprecated
823 default:
824 bReadonly = true;
827 return bReadonly;
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;
841 SetModified();
845 inline sal_Int32 SvtSecurityOptions_Impl::GetMacroSecurityLevel() const
847 return m_nSecLevel;
850 inline bool SvtSecurityOptions_Impl::IsMacroDisabled() const
852 return m_bDisableMacros;
855 void SvtSecurityOptions_Impl::SetMacroSecurityLevel( sal_Int32 _nLevel )
857 if( !m_bROSecLevel )
859 if( _nLevel > 3 || _nLevel < 0 )
860 _nLevel = 3;
862 if( m_nSecLevel != _nLevel )
864 m_nSecLevel = _nLevel;
865 SetModified();
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;
881 SetModified();
885 bool SvtSecurityOptions_Impl::IsOptionSet( SvtSecurityOptions::EOption eOption ) const
887 bool* pValue;
888 bool* pRO;
889 bool bRet = false;
891 if( ( const_cast< SvtSecurityOptions_Impl* >( this ) )->GetOption( eOption, pValue, pRO ) )
892 bRet = *pValue;
894 return bRet;
897 bool SvtSecurityOptions_Impl::SetOption( SvtSecurityOptions::EOption eOption, bool bValue )
899 bool* pValue;
900 bool* pRO;
901 bool bRet = false;
903 if( GetOption( eOption, pValue, pRO ) )
905 if( !*pRO )
907 bRet = true;
908 if( *pValue != bValue )
910 *pValue = bValue;
911 SetModified();
916 return bRet;
919 bool SvtSecurityOptions_Impl::IsOptionEnabled( SvtSecurityOptions::EOption eOption ) const
921 bool* pValue;
922 bool* pRO;
923 bool bRet = false;
925 if( ( const_cast< SvtSecurityOptions_Impl* >( this ) )->GetOption( eOption, pValue, pRO ) )
926 bRet = !*pRO;
928 return bRet;
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 ...
971 ++m_nRefCount;
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.
986 --m_nRefCount;
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:
1022 return true;
1024 // fall through
1025 case INET_PROT_SLOT:
1026 return referer.equalsIgnoreAsciiCase("private:user")
1027 || isTrustedLocationUri(referer);
1028 default:
1029 return true;
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();
1043 ++i)
1045 if (UCBContentHelper::IsSubPath(
1046 m_pDataContainer->m_seqSecureURLs[i], uri))
1048 return true;
1051 return false;
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 );
1102 namespace
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;
1125 SetModified();
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;
1140 SetModified();
1144 bool SvtSecurityOptions_Impl::IsWarningEnabled() const
1146 return m_bWarning;
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)
1154 m_bWarning = bSet;
1155 SetModified();
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;
1170 SetModified();
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: */