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