1*2c696243SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*2c696243SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*2c696243SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*2c696243SAndrew Rist * distributed with this work for additional information
6*2c696243SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*2c696243SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*2c696243SAndrew Rist * "License"); you may not use this file except in compliance
9*2c696243SAndrew Rist * with the License. You may obtain a copy of the License at
10*2c696243SAndrew Rist *
11*2c696243SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*2c696243SAndrew Rist *
13*2c696243SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*2c696243SAndrew Rist * software distributed under the License is distributed on an
15*2c696243SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2c696243SAndrew Rist * KIND, either express or implied. See the License for the
17*2c696243SAndrew Rist * specific language governing permissions and limitations
18*2c696243SAndrew Rist * under the License.
19*2c696243SAndrew Rist *
20*2c696243SAndrew Rist *************************************************************/
21*2c696243SAndrew Rist
22*2c696243SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_scripting.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp>
28cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
30cdf0e10cSrcweir #include <com/sun/star/lang/WrappedTargetException.hpp>
31cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
32cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
33cdf0e10cSrcweir #include <com/sun/star/beans/UnknownPropertyException.hpp>
34cdf0e10cSrcweir #include <com/sun/star/container/XNameReplace.hpp>
35cdf0e10cSrcweir #include <com/sun/star/util/XChangesBatch.hpp>
36cdf0e10cSrcweir #include <com/sun/star/util/XMacroExpander.hpp>
37cdf0e10cSrcweir #include <com/sun/star/util/XStringSubstitution.hpp>
38cdf0e10cSrcweir #include <com/sun/star/awt/XDialog.hpp>
39cdf0e10cSrcweir #include <com/sun/star/security/AccessControlException.hpp>
40cdf0e10cSrcweir #include <com/sun/star/security/RuntimePermission.hpp>
41cdf0e10cSrcweir #include <drafts/com/sun/star/script/framework/storage/XScriptStorageManager.hpp>
42cdf0e10cSrcweir #include <drafts/com/sun/star/script/framework/storage/XScriptInfoAccess.hpp>
43cdf0e10cSrcweir #include "ScriptSecurityManager.hxx"
44cdf0e10cSrcweir #include <util/util.hxx>
45cdf0e10cSrcweir #include <util/scriptingconstants.hxx>
46cdf0e10cSrcweir #include <tools/diagnose_ex.h>
47cdf0e10cSrcweir
48cdf0e10cSrcweir using namespace ::rtl;
49cdf0e10cSrcweir using namespace ::osl;
50cdf0e10cSrcweir using namespace ::com::sun::star;
51cdf0e10cSrcweir using namespace ::com::sun::star::uno;
52cdf0e10cSrcweir using namespace ::drafts::com::sun::star::script::framework;
53cdf0e10cSrcweir
54cdf0e10cSrcweir // is this in the utils?
55cdf0e10cSrcweir const char* const SCRIPTSTORAGEMANAGER_SERVICE =
56cdf0e10cSrcweir "/singletons/drafts.com.sun.star.script.framework.storage.theScriptStorageManager";
57cdf0e10cSrcweir
58cdf0e10cSrcweir namespace scripting_securitymgr
59cdf0e10cSrcweir {
60cdf0e10cSrcweir
61cdf0e10cSrcweir static OUString s_configProv = ::rtl::OUString::createFromAscii(
62cdf0e10cSrcweir "com.sun.star.configuration.ConfigurationProvider");
63cdf0e10cSrcweir
64cdf0e10cSrcweir static OUString s_configAccess = ::rtl::OUString::createFromAscii(
65cdf0e10cSrcweir "com.sun.star.configuration.ConfigurationAccess");
66cdf0e10cSrcweir
67cdf0e10cSrcweir static OUString s_configUpdate = ::rtl::OUString::createFromAscii(
68cdf0e10cSrcweir "com.sun.star.configuration.ConfigurationUpdateAccess");
69cdf0e10cSrcweir
70cdf0e10cSrcweir static OUString s_securityDialog = ::rtl::OUString::createFromAscii(
71cdf0e10cSrcweir "com.sun.star.script.framework.security.SecurityDialog");
72cdf0e10cSrcweir
73cdf0e10cSrcweir static const int PERMISSION_NEVER = 0;
74cdf0e10cSrcweir static const int PERMISSION_PATHLIST = 1;
75cdf0e10cSrcweir static const int PERMISSION_ALWAYS = 2;
76cdf0e10cSrcweir
77cdf0e10cSrcweir static const int ALLOW_RUN = 1;
78cdf0e10cSrcweir static const int ADD_TO_PATH = 2;
79cdf0e10cSrcweir
80cdf0e10cSrcweir //*************************************************************************
81cdf0e10cSrcweir // ScriptSecurityManager Constructor
ScriptSecurityManager(const Reference<XComponentContext> & xContext)82cdf0e10cSrcweir ScriptSecurityManager::ScriptSecurityManager(
83cdf0e10cSrcweir const Reference< XComponentContext > & xContext ) throw ( RuntimeException )
84cdf0e10cSrcweir : m_xContext( xContext, UNO_SET_THROW )
85cdf0e10cSrcweir {
86cdf0e10cSrcweir OSL_TRACE( "< ScriptSecurityManager ctor called >\n" );
87cdf0e10cSrcweir
88cdf0e10cSrcweir // get the service manager from the context
89cdf0e10cSrcweir Reference< lang::XMultiComponentFactory > xMgr( m_xContext->getServiceManager(), UNO_SET_THROW );
90cdf0e10cSrcweir
91cdf0e10cSrcweir // create an instance of the ConfigurationProvider
92cdf0e10cSrcweir m_xConfigProvFactory.set( xMgr->createInstanceWithContext( s_configProv, m_xContext ), UNO_QUERY_THROW );
93cdf0e10cSrcweir }
94cdf0e10cSrcweir
addScriptStorage(rtl::OUString scriptStorageURL,sal_Int32 storageID)95cdf0e10cSrcweir void ScriptSecurityManager::addScriptStorage( rtl::OUString scriptStorageURL,
96cdf0e10cSrcweir sal_Int32 storageID)
97cdf0e10cSrcweir throw ( RuntimeException )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir Permission_Hash::const_iterator ph_it = m_permissionSettings.find( scriptStorageURL );
100cdf0e10cSrcweir if ( ph_it != m_permissionSettings.end() )
101cdf0e10cSrcweir {
102cdf0e10cSrcweir OSL_TRACE( "ScriptSecurityManager::addScriptStorage: already called for %s",
103cdf0e10cSrcweir ::rtl::OUStringToOString( scriptStorageURL,
104cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer);
105cdf0e10cSrcweir return;
106cdf0e10cSrcweir }
107cdf0e10cSrcweir StoragePerm newPerm;
108cdf0e10cSrcweir newPerm.scriptStorageURL=scriptStorageURL;
109cdf0e10cSrcweir newPerm.storageID=storageID;
110cdf0e10cSrcweir
111cdf0e10cSrcweir // we err on the side of caution!!
112cdf0e10cSrcweir newPerm.execPermission=sal_False;
113cdf0e10cSrcweir
114cdf0e10cSrcweir //need to check if storage has any scripts
115cdf0e10cSrcweir try
116cdf0e10cSrcweir {
117cdf0e10cSrcweir // we have some scripts so read config & decide on that basis
118cdf0e10cSrcweir // Setup flags: m_runMacroSetting, m_warning, m_confirmationRequired,
119cdf0e10cSrcweir readConfiguration();
120cdf0e10cSrcweir }
121cdf0e10cSrcweir catch ( RuntimeException & rte )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir OSL_TRACE( "ScriptSecurityManager::addScriptStorage: caught RuntimeException: %s",
124cdf0e10cSrcweir ::rtl::OUStringToOString( rte.Message,
125cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer);
126cdf0e10cSrcweir throw RuntimeException(
127cdf0e10cSrcweir OUSTR( "ScriptSecurityManager::addScriptStorage: caught RuntimeException" ).concat( rte.Message ),
128cdf0e10cSrcweir Reference< XInterface >() );
129cdf0e10cSrcweir }
130cdf0e10cSrcweir
131cdf0e10cSrcweir switch( m_runMacroSetting )
132cdf0e10cSrcweir {
133cdf0e10cSrcweir case PERMISSION_NEVER: // never
134cdf0e10cSrcweir {
135cdf0e10cSrcweir OSL_TRACE("never run");
136cdf0e10cSrcweir break;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir case PERMISSION_PATHLIST: // according to path list
139cdf0e10cSrcweir {
140cdf0e10cSrcweir OSL_TRACE("according to path");
141cdf0e10cSrcweir // check path
142cdf0e10cSrcweir rtl::OUString path = scriptStorageURL.copy( 0, scriptStorageURL.lastIndexOf( '/' ) );
143cdf0e10cSrcweir OSL_TRACE( "no of elts in path list = %d",
144cdf0e10cSrcweir (int)m_secureURL.getLength() );
145cdf0e10cSrcweir bool match = isSecureURL( path );
146cdf0e10cSrcweir if( match && ( m_warning == sal_True ) )
147cdf0e10cSrcweir {
148cdf0e10cSrcweir OSL_TRACE("path match & warning dialog");
149cdf0e10cSrcweir int result = (int)executeStandardDialog();
150cdf0e10cSrcweir OSL_TRACE("result = %d", (int)result);
151cdf0e10cSrcweir if ( (result&ALLOW_RUN) == ALLOW_RUN )
152cdf0e10cSrcweir {
153cdf0e10cSrcweir newPerm.execPermission=sal_True;
154cdf0e10cSrcweir }
155cdf0e10cSrcweir break;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir else if ( match )
158cdf0e10cSrcweir {
159cdf0e10cSrcweir OSL_TRACE("path match & no warning dialog");
160cdf0e10cSrcweir newPerm.execPermission=sal_True;
161cdf0e10cSrcweir break;
162cdf0e10cSrcweir }
163cdf0e10cSrcweir else if( m_confirmationRequired == sal_True )
164cdf0e10cSrcweir {
165cdf0e10cSrcweir OSL_TRACE("no path match & confirmation dialog");
166cdf0e10cSrcweir int result = (int)executePathDialog( path );
167cdf0e10cSrcweir OSL_TRACE("result = %d", (int)result);
168cdf0e10cSrcweir if ( (result&ALLOW_RUN) == ALLOW_RUN )
169cdf0e10cSrcweir {
170cdf0e10cSrcweir newPerm.execPermission=sal_True;
171cdf0e10cSrcweir }
172cdf0e10cSrcweir if ( (result&ADD_TO_PATH) == ADD_TO_PATH )
173cdf0e10cSrcweir {
174cdf0e10cSrcweir /* if checkbox clicked then need to add path to registry*/
175cdf0e10cSrcweir addToSecurePaths(path);
176cdf0e10cSrcweir }
177cdf0e10cSrcweir }
178cdf0e10cSrcweir break;
179cdf0e10cSrcweir }
180cdf0e10cSrcweir case PERMISSION_ALWAYS: // always
181cdf0e10cSrcweir if( m_warning == sal_True )
182cdf0e10cSrcweir {
183cdf0e10cSrcweir OSL_TRACE("always & warning dialog");
184cdf0e10cSrcweir short result = executeStandardDialog();
185cdf0e10cSrcweir if ( (result&ALLOW_RUN) == ALLOW_RUN )
186cdf0e10cSrcweir {
187cdf0e10cSrcweir newPerm.execPermission=sal_True;
188cdf0e10cSrcweir }
189cdf0e10cSrcweir }
190cdf0e10cSrcweir else
191cdf0e10cSrcweir {
192cdf0e10cSrcweir OSL_TRACE("always & no warning dialog");
193cdf0e10cSrcweir newPerm.execPermission=sal_True;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir break;
196cdf0e10cSrcweir default:
197cdf0e10cSrcweir //
198cdf0e10cSrcweir throw RuntimeException(
199cdf0e10cSrcweir OUSTR( "ScriptSecurityManager::addScriptStorage got invalid OfficeBasic setting"),
200cdf0e10cSrcweir Reference< XInterface > ());
201cdf0e10cSrcweir }
202cdf0e10cSrcweir
203cdf0e10cSrcweir if ( newPerm.execPermission == sal_True )
204cdf0e10cSrcweir {
205cdf0e10cSrcweir OSL_TRACE("setting exec permission to true for %s",
206cdf0e10cSrcweir ::rtl::OUStringToOString( scriptStorageURL,
207cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer );
208cdf0e10cSrcweir }
209cdf0e10cSrcweir else
210cdf0e10cSrcweir {
211cdf0e10cSrcweir OSL_TRACE("setting exec permission to false for %s",
212cdf0e10cSrcweir ::rtl::OUStringToOString( scriptStorageURL,
213cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer );
214cdf0e10cSrcweir }
215cdf0e10cSrcweir
216cdf0e10cSrcweir m_permissionSettings[ scriptStorageURL ] = newPerm;
217cdf0e10cSrcweir }
218cdf0e10cSrcweir
isSecureURL(const OUString & path)219cdf0e10cSrcweir bool ScriptSecurityManager::isSecureURL( const OUString & path )
220cdf0e10cSrcweir {
221cdf0e10cSrcweir bool match = false;
222cdf0e10cSrcweir OSL_TRACE( "no of elts in path list = %d",
223cdf0e10cSrcweir (int)m_secureURL.getLength() );
224cdf0e10cSrcweir OSL_TRACE("document path: %s",
225cdf0e10cSrcweir ::rtl::OUStringToOString( path,
226cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer);
227cdf0e10cSrcweir int length = m_secureURL.getLength();
228cdf0e10cSrcweir for( int j = 0; j < length ; j++ )
229cdf0e10cSrcweir {
230cdf0e10cSrcweir OSL_TRACE("path list element: %s",
231cdf0e10cSrcweir ::rtl::OUStringToOString( m_secureURL[j],
232cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer);
233cdf0e10cSrcweir #ifdef WIN32
234cdf0e10cSrcweir OSL_TRACE("case insensitive comparison");
235cdf0e10cSrcweir if( path.equalsIgnoreAsciiCase( m_secureURL[j] ) )
236cdf0e10cSrcweir #else
237cdf0e10cSrcweir OSL_TRACE("case sensitive comparison");
238cdf0e10cSrcweir if( path.equals( m_secureURL[j] ) )
239cdf0e10cSrcweir #endif
240cdf0e10cSrcweir {
241cdf0e10cSrcweir match = true;
242cdf0e10cSrcweir break;
243cdf0e10cSrcweir }
244cdf0e10cSrcweir }
245cdf0e10cSrcweir return match;
246cdf0e10cSrcweir }
247cdf0e10cSrcweir
executeStandardDialog()248cdf0e10cSrcweir short ScriptSecurityManager::executeStandardDialog()
249cdf0e10cSrcweir throw ( RuntimeException )
250cdf0e10cSrcweir {
251cdf0e10cSrcweir OUString dummyString;
252cdf0e10cSrcweir return executeDialog( dummyString );
253cdf0e10cSrcweir }
254cdf0e10cSrcweir
executePathDialog(const OUString & path)255cdf0e10cSrcweir short ScriptSecurityManager::executePathDialog( const OUString & path )
256cdf0e10cSrcweir throw ( RuntimeException )
257cdf0e10cSrcweir {
258cdf0e10cSrcweir return executeDialog( path );
259cdf0e10cSrcweir }
260cdf0e10cSrcweir
executeDialog(const OUString & path)261cdf0e10cSrcweir short ScriptSecurityManager::executeDialog( const OUString & path )
262cdf0e10cSrcweir throw ( RuntimeException )
263cdf0e10cSrcweir {
264cdf0e10cSrcweir Sequence < Any > aArgs;
265cdf0e10cSrcweir if( path.getLength() != 0 )
266cdf0e10cSrcweir {
267cdf0e10cSrcweir OSL_TRACE("reallocing");
268cdf0e10cSrcweir aArgs.realloc(1);
269cdf0e10cSrcweir aArgs[ 0 ] <<= path;
270cdf0e10cSrcweir }
271cdf0e10cSrcweir short result;
272cdf0e10cSrcweir try
273cdf0e10cSrcweir {
274cdf0e10cSrcweir Reference< lang::XMultiComponentFactory > xMgr( m_xContext->getServiceManager(), UNO_SET_THROW );
275cdf0e10cSrcweir Reference< awt::XDialog > xDialog(
276cdf0e10cSrcweir xMgr->createInstanceWithArgumentsAndContext( s_securityDialog, aArgs, m_xContext ),
277cdf0e10cSrcweir UNO_QUERY_THROW );
278cdf0e10cSrcweir result = xDialog->execute();
279cdf0e10cSrcweir Reference< lang::XComponent > xComponent( xDialog, UNO_QUERY_THROW );
280cdf0e10cSrcweir xComponent->dispose();
281cdf0e10cSrcweir }
282cdf0e10cSrcweir catch ( RuntimeException & rte )
283cdf0e10cSrcweir {
284cdf0e10cSrcweir throw RuntimeException(
285cdf0e10cSrcweir OUSTR( "ScriptSecurityManager::executeDialog: caught RuntimeException: ").concat( rte.Message ),
286cdf0e10cSrcweir Reference< XInterface > ());
287cdf0e10cSrcweir }
288cdf0e10cSrcweir catch ( Exception & e )
289cdf0e10cSrcweir {
290cdf0e10cSrcweir throw RuntimeException(
291cdf0e10cSrcweir OUSTR( "ScriptSecurityManager::executeDialog: caught Exception: ").concat( e.Message ),
292cdf0e10cSrcweir Reference< XInterface > ());
293cdf0e10cSrcweir }
294cdf0e10cSrcweir return result;
295cdf0e10cSrcweir }
296cdf0e10cSrcweir
297cdf0e10cSrcweir /**
298cdf0e10cSrcweir * checks to see whether the requested ScriptPermission is allowed.
299cdf0e10cSrcweir * This was modelled after the Java AccessController, but at this time
300cdf0e10cSrcweir * we can't see a good reason not to return a bool, rather than throw
301cdf0e10cSrcweir * an exception if the request is not granted (as is the case in Java).
302cdf0e10cSrcweir */
checkPermission(const OUString & scriptStorageURL,const OUString & permissionRequest)303cdf0e10cSrcweir void ScriptSecurityManager::checkPermission( const OUString & scriptStorageURL,
304cdf0e10cSrcweir const OUString & permissionRequest )
305cdf0e10cSrcweir throw ( RuntimeException, lang::IllegalArgumentException, security::AccessControlException )
306cdf0e10cSrcweir {
307cdf0e10cSrcweir if( permissionRequest.equals( OUString::createFromAscii( "execute" ) ) )
308cdf0e10cSrcweir {
309cdf0e10cSrcweir OSL_TRACE(
310cdf0e10cSrcweir "ScriptSecurityManager::checkPermission: execute permission request for %s",
311cdf0e10cSrcweir ::rtl::OUStringToOString( scriptStorageURL,
312cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer);
313cdf0e10cSrcweir Permission_Hash::const_iterator ph_it = m_permissionSettings.find( scriptStorageURL );
314cdf0e10cSrcweir Permission_Hash::const_iterator ph_itend =
315cdf0e10cSrcweir m_permissionSettings.end();
316cdf0e10cSrcweir if ( ph_it != ph_itend )
317cdf0e10cSrcweir {
318cdf0e10cSrcweir if ( ph_it->second.execPermission )
319cdf0e10cSrcweir {
320cdf0e10cSrcweir return;
321cdf0e10cSrcweir }
322cdf0e10cSrcweir else
323cdf0e10cSrcweir {
324cdf0e10cSrcweir OSL_TRACE( "permission refused" );
325cdf0e10cSrcweir Any aPermission;
326cdf0e10cSrcweir security::RuntimePermission permission;
327cdf0e10cSrcweir permission.Name = OUString::createFromAscii( "execute" ).concat( scriptStorageURL );
328cdf0e10cSrcweir aPermission <<= permission;
329cdf0e10cSrcweir throw security::AccessControlException(
330cdf0e10cSrcweir OUString::createFromAscii( "ScriptSecurityManager::checkPermission: no execute permission for URL" ).concat( scriptStorageURL ),
331cdf0e10cSrcweir Reference< XInterface > (), aPermission );
332cdf0e10cSrcweir }
333cdf0e10cSrcweir }
334cdf0e10cSrcweir // we should never get here!!
335cdf0e10cSrcweir throw lang::IllegalArgumentException( OUString::createFromAscii( "ScriptSecurityManager::checkPermission: storageURL not found" ), Reference< XInterface > (), 0 );
336cdf0e10cSrcweir }
337cdf0e10cSrcweir // inappropriate permission request
338cdf0e10cSrcweir throw lang::IllegalArgumentException( OUString::createFromAscii( "ScriptSecurityManager::checkPermission: storageURL not found" ), Reference< XInterface > (), 1 );
339cdf0e10cSrcweir }
340cdf0e10cSrcweir
removePermissionSettings(::rtl::OUString & scriptStorageURL)341cdf0e10cSrcweir void ScriptSecurityManager::removePermissionSettings ( ::rtl::OUString & scriptStorageURL )
342cdf0e10cSrcweir {
343cdf0e10cSrcweir Permission_Hash::const_iterator ph_it =
344cdf0e10cSrcweir m_permissionSettings.find( scriptStorageURL );
345cdf0e10cSrcweir
346cdf0e10cSrcweir if ( ph_it == m_permissionSettings.end() )
347cdf0e10cSrcweir {
348cdf0e10cSrcweir OSL_TRACE( "Entry for storage url %s doesn't exist in map",
349cdf0e10cSrcweir ::rtl::OUStringToOString( scriptStorageURL,
350cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer);
351cdf0e10cSrcweir return;
352cdf0e10cSrcweir }
353cdf0e10cSrcweir
354cdf0e10cSrcweir // erase the entry from the hash
355cdf0e10cSrcweir m_permissionSettings.erase( scriptStorageURL );
356cdf0e10cSrcweir
357cdf0e10cSrcweir }
358cdf0e10cSrcweir
readConfiguration()359cdf0e10cSrcweir void ScriptSecurityManager::readConfiguration()
360cdf0e10cSrcweir throw ( RuntimeException)
361cdf0e10cSrcweir {
362cdf0e10cSrcweir try
363cdf0e10cSrcweir {
364cdf0e10cSrcweir beans::PropertyValue configPath;
365cdf0e10cSrcweir configPath.Name = ::rtl::OUString::createFromAscii( "nodepath" );
366cdf0e10cSrcweir configPath.Value <<= ::rtl::OUString::createFromAscii( "org.openoffice.Office.Common/Security/Scripting" );
367cdf0e10cSrcweir Sequence < Any > aargs( 1 );
368cdf0e10cSrcweir aargs[ 0 ] <<= configPath;
369cdf0e10cSrcweir ENSURE_OR_THROW( m_xConfigProvFactory.is(),
370cdf0e10cSrcweir "ScriptSecurityManager::readConfiguration: ConfigProviderFactory no longer valid!" );
371cdf0e10cSrcweir // get the XPropertySet interface from the ConfigurationAccess service
372cdf0e10cSrcweir Reference < beans::XPropertySet > xPropSet( m_xConfigProvFactory->createInstanceWithArguments( s_configAccess, aargs ), UNO_QUERY_THROW );
373cdf0e10cSrcweir
374cdf0e10cSrcweir m_confirmationRequired = sal_True;
375cdf0e10cSrcweir OSL_VERIFY( xPropSet->getPropertyValue( OUSTR( "Confirmation" ) ) >>= m_confirmationRequired );
376cdf0e10cSrcweir if ( m_confirmationRequired == sal_True )
377cdf0e10cSrcweir {
378cdf0e10cSrcweir OSL_TRACE( "ScriptSecurityManager:readConfiguration: confirmation is true" );
379cdf0e10cSrcweir }
380cdf0e10cSrcweir else
381cdf0e10cSrcweir {
382cdf0e10cSrcweir OSL_TRACE( "ScriptSecurityManager:readConfiguration: confirmation is false" );
383cdf0e10cSrcweir }
384cdf0e10cSrcweir
385cdf0e10cSrcweir m_warning = true;
386cdf0e10cSrcweir OSL_VERIFY( xPropSet->getPropertyValue( OUSTR( "Warning" ) ) >>= m_warning );
387cdf0e10cSrcweir
388cdf0e10cSrcweir if ( m_warning == sal_True )
389cdf0e10cSrcweir {
390cdf0e10cSrcweir OSL_TRACE( "ScriptSecurityManager:readConfiguration: warning is true" );
391cdf0e10cSrcweir }
392cdf0e10cSrcweir else
393cdf0e10cSrcweir {
394cdf0e10cSrcweir OSL_TRACE( "ScriptSecurityManager:readConfiguration: warning is false" );
395cdf0e10cSrcweir }
396cdf0e10cSrcweir
397cdf0e10cSrcweir m_runMacroSetting = sal_True;
398cdf0e10cSrcweir OSL_VERIFY( xPropSet->getPropertyValue( OUSTR( "OfficeBasic" ) ) >>= m_runMacroSetting );
399cdf0e10cSrcweir OSL_TRACE( "ScriptSecurityManager:readConfiguration: OfficeBasic = %d", m_runMacroSetting );
400cdf0e10cSrcweir
401cdf0e10cSrcweir m_secureURL = ::rtl::OUString();
402cdf0e10cSrcweir OSL_VERIFY( xPropSet->getPropertyValue( OUSTR( "SecureURL" ) ) >>= m_secureURL );
403cdf0e10cSrcweir }
404cdf0e10cSrcweir catch ( beans::UnknownPropertyException & upe )
405cdf0e10cSrcweir {
406cdf0e10cSrcweir throw RuntimeException(
407cdf0e10cSrcweir OUSTR( "ScriptSecurityManager:readConfiguration: Attempt to read unknown property: " ).concat( upe.Message ),
408cdf0e10cSrcweir Reference< XInterface > () );
409cdf0e10cSrcweir }
410cdf0e10cSrcweir catch ( lang::WrappedTargetException & wte )
411cdf0e10cSrcweir {
412cdf0e10cSrcweir throw RuntimeException(
413cdf0e10cSrcweir OUSTR( "ScriptSecurityManager:readConfiguration: wrapped target exception? :" ).concat( wte.Message ),
414cdf0e10cSrcweir Reference< XInterface > () );
415cdf0e10cSrcweir }
416cdf0e10cSrcweir catch ( Exception & e )
417cdf0e10cSrcweir {
418cdf0e10cSrcweir OSL_TRACE( "Unknown exception in readconf: %s",
419cdf0e10cSrcweir ::rtl::OUStringToOString(e.Message ,
420cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer );
421cdf0e10cSrcweir throw RuntimeException(
422cdf0e10cSrcweir OUSTR( "ScriptSecurityManager:readConfiguration: exception? :" ).concat( e.Message ),
423cdf0e10cSrcweir Reference< XInterface > () );
424cdf0e10cSrcweir }
425cdf0e10cSrcweir #ifdef _DEBUG
426cdf0e10cSrcweir catch ( ... )
427cdf0e10cSrcweir {
428cdf0e10cSrcweir OSL_TRACE( "Completely Unknown exception in readconf!!!!!!");
429cdf0e10cSrcweir throw RuntimeException(
430cdf0e10cSrcweir OUSTR( "ScriptSecurityManager:readConfiguration: exception? :" ),
431cdf0e10cSrcweir Reference< XInterface > () );
432cdf0e10cSrcweir }
433cdf0e10cSrcweir #endif
434cdf0e10cSrcweir
435cdf0e10cSrcweir int length = m_secureURL.getLength();
436cdf0e10cSrcweir
437cdf0e10cSrcweir // PathSubstitution needed to interpret variables found in config
438cdf0e10cSrcweir Reference< lang::XMultiComponentFactory > xMgr( m_xContext->getServiceManager(), UNO_SET_THROW );
439cdf0e10cSrcweir Reference< XInterface > xInterface = );
440cdf0e10cSrcweir Reference< util::XStringSubstitution > xStringSubstitution(
441cdf0e10cSrcweir xMgr->createInstanceWithContext(
442cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "com.sun.star.util.PathSubstitution" ), m_xContext
443cdf0e10cSrcweir ),
444cdf0e10cSrcweir UNO_QUERY_THROW
445cdf0e10cSrcweir );
446cdf0e10cSrcweir for( int i = 0; i < length; i++ )
447cdf0e10cSrcweir {
448cdf0e10cSrcweir OSL_TRACE( "ScriptSecurityManager:readConfiguration path = %s",
449cdf0e10cSrcweir ::rtl::OUStringToOString(m_secureURL[i] ,
450cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer );
451cdf0e10cSrcweir
452cdf0e10cSrcweir OSL_TRACE( "ScriptSecurityManager: subpath = %s",
453cdf0e10cSrcweir ::rtl::OUStringToOString(
454cdf0e10cSrcweir xStringSubstitution->substituteVariables( m_secureURL[i], true ),
455cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer );
456cdf0e10cSrcweir m_secureURL[i] = xStringSubstitution->substituteVariables( m_secureURL[i], true );
457cdf0e10cSrcweir }
458cdf0e10cSrcweir #ifdef _DEBUG
459cdf0e10cSrcweir int length2 = m_secureURL.getLength();
460cdf0e10cSrcweir for( int j = 0; j < length2 ; j++ )
461cdf0e10cSrcweir {
462cdf0e10cSrcweir OSL_TRACE( "ScriptSecurityManager: path = %s",
463cdf0e10cSrcweir ::rtl::OUStringToOString(m_secureURL[j] ,
464cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ).pData->buffer );
465cdf0e10cSrcweir }
466cdf0e10cSrcweir #endif
467cdf0e10cSrcweir }
468cdf0e10cSrcweir
addToSecurePaths(const OUString & path)469cdf0e10cSrcweir void ScriptSecurityManager::addToSecurePaths( const OUString & path )
470cdf0e10cSrcweir throw ( RuntimeException )
471cdf0e10cSrcweir {
472cdf0e10cSrcweir OSL_TRACE( "--->ScriptSecurityManager::addToSecurePaths" );
473cdf0e10cSrcweir beans::PropertyValue configPath;
474cdf0e10cSrcweir configPath.Name = ::rtl::OUString::createFromAscii( "nodepath" );
475cdf0e10cSrcweir configPath.Value <<= ::rtl::OUString::createFromAscii( "org.openoffice.Office.Common/Security/Scripting" );
476cdf0e10cSrcweir Sequence < Any > aargs( 1 );
477cdf0e10cSrcweir aargs[ 0 ] <<= configPath;
478cdf0e10cSrcweir Reference < container::XNameReplace > xNameReplace(
479cdf0e10cSrcweir m_xConfigProvFactory->createInstanceWithArguments( s_configUpdate, aargs ), UNO_QUERY_THROW );
480cdf0e10cSrcweir Reference < util::XChangesBatch > xChangesBatch( xNameReplace, UNO_QUERY_THROW );
481cdf0e10cSrcweir
482cdf0e10cSrcweir OSL_TRACE( "--->ScriptSecurityManager::addToSecurePaths: after if stuff" );
483cdf0e10cSrcweir Reference < beans::XPropertySet > xPropSet( xInterface, UNO_QUERY );
484cdf0e10cSrcweir css::uno::Sequence< rtl::OUString > newSecureURL;
485cdf0e10cSrcweir Any value;
486cdf0e10cSrcweir OUString pathListPropName = OUSTR ( "SecureURL" );
487cdf0e10cSrcweir value=xPropSet->getPropertyValue( pathListPropName );
488cdf0e10cSrcweir if ( sal_False == ( value >>= newSecureURL ) )
489cdf0e10cSrcweir {
490cdf0e10cSrcweir throw RuntimeException(
491cdf0e10cSrcweir OUSTR( "ScriptSecurityManager::addToSecurePaths: can't get SecureURL setting" ),
492cdf0e10cSrcweir Reference< XInterface > () );
493cdf0e10cSrcweir }
494cdf0e10cSrcweir try
495cdf0e10cSrcweir {
496cdf0e10cSrcweir sal_Int32 length = newSecureURL.getLength();
497cdf0e10cSrcweir newSecureURL.realloc( length + 1 );
498cdf0e10cSrcweir newSecureURL[ length ] = path;
499cdf0e10cSrcweir Any aNewSecureURL;
500cdf0e10cSrcweir aNewSecureURL <<= newSecureURL;
501cdf0e10cSrcweir xNameReplace->replaceByName( pathListPropName, aNewSecureURL );
502cdf0e10cSrcweir xChangesBatch->commitChanges();
503cdf0e10cSrcweir m_secureURL = newSecureURL;
504cdf0e10cSrcweir }
505cdf0e10cSrcweir catch ( Exception & e )
506cdf0e10cSrcweir {
507cdf0e10cSrcweir OSL_TRACE( "Error updating secure paths: " );
508cdf0e10cSrcweir throw RuntimeException(
509cdf0e10cSrcweir OUSTR( "ScriptSecurityManager::addToSecurePaths: error updating SecureURL setting" ).concat( e.Message ),
510cdf0e10cSrcweir Reference< XInterface > () );
511cdf0e10cSrcweir }
512cdf0e10cSrcweir }
513cdf0e10cSrcweir
514cdf0e10cSrcweir //*************************************************************************
515cdf0e10cSrcweir // ScriptSecurityManager Destructor
~ScriptSecurityManager()516cdf0e10cSrcweir ScriptSecurityManager::~ScriptSecurityManager()
517cdf0e10cSrcweir {
518cdf0e10cSrcweir OSL_TRACE( "< ScriptSecurityManager dtor called >\n" );
519cdf0e10cSrcweir }
520cdf0e10cSrcweir
521cdf0e10cSrcweir } // Namespace
522