1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_cppuhelper.hxx" 26 27 #include <cppuhelper/access_control.hxx> 28 29 #include <com/sun/star/security/XAccessController.hpp> 30 #include <com/sun/star/security/RuntimePermission.hpp> 31 #include <com/sun/star/io/FilePermission.hpp> 32 #include <com/sun/star/connection/SocketPermission.hpp> 33 34 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) 35 36 37 using namespace ::rtl; 38 using namespace ::osl; 39 using namespace ::com::sun::star; 40 using namespace ::com::sun::star::uno; 41 42 namespace 43 { 44 inline OUString str_ac_singleton() 45 { 46 return OUSTR("/singletons/com.sun.star.security.theAccessController"); 47 } 48 } 49 50 namespace cppu 51 { 52 //__________________________________________________________________________________________________ 53 AccessControl::AccessControl( Reference< XComponentContext > const & xContext ) 54 { 55 if (! (xContext->getValueByName( str_ac_singleton() ) >>= m_xController)) 56 { 57 throw SecurityException( 58 OUSTR("no access controller!"), Reference< XInterface >() ); 59 } 60 } 61 //__________________________________________________________________________________________________ 62 AccessControl::AccessControl( 63 Reference< security::XAccessController > const & xController ) 64 : m_xController( xController ) 65 { 66 if (! m_xController.is()) 67 { 68 throw SecurityException( 69 OUSTR("no access controller!"), Reference< XInterface >() ); 70 } 71 } 72 //__________________________________________________________________________________________________ 73 AccessControl::AccessControl( AccessControl const & ac ) 74 : m_xController( ac.m_xController ) 75 { 76 if (! m_xController.is()) 77 { 78 throw SecurityException( 79 OUSTR("no access controller!"), Reference< XInterface >() ); 80 } 81 } 82 83 #ifdef SAL_W32 84 #pragma pack(push, 8) 85 #endif 86 // binary comp. to all Permission structs 87 struct __permission 88 { 89 rtl_uString * m_str1; 90 rtl_uString * m_str2; 91 }; 92 #ifdef SAL_W32 93 #pragma pack(pop) 94 #endif 95 96 //-------------------------------------------------------------------------------------------------- 97 inline void __checkPermission( 98 Reference< security::XAccessController > const & xController, 99 Type const & type, rtl_uString * str1, rtl_uString * str2 ) 100 { 101 __permission perm; 102 perm.m_str1 = str1; 103 perm.m_str2 = str2; 104 105 uno_Any a; 106 a.pType = type.getTypeLibType(); 107 a.pData = &perm; 108 109 xController->checkPermission( * static_cast< Any * >( &a ) ); 110 } 111 //__________________________________________________________________________________________________ 112 void AccessControl::checkRuntimePermission( 113 OUString const & name ) 114 { 115 __checkPermission( 116 m_xController, 117 ::getCppuType( (security::RuntimePermission *)0 ), name.pData, 0 ); 118 } 119 //__________________________________________________________________________________________________ 120 void AccessControl::checkFilePermission( 121 OUString const & url, 122 OUString const & actions ) 123 { 124 __checkPermission( 125 m_xController, 126 ::getCppuType( (io::FilePermission *)0 ), url.pData, actions.pData ); 127 } 128 //__________________________________________________________________________________________________ 129 void AccessControl::checkSocketPermission( 130 OUString const & host, 131 OUString const & actions ) 132 { 133 __checkPermission( 134 m_xController, 135 ::getCppuType( (connection::SocketPermission *)0 ), host.pData, actions.pData ); 136 } 137 138 } 139