1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_cppuhelper.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <cppuhelper/access_control.hxx> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <com/sun/star/security/XAccessController.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/security/RuntimePermission.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/io/FilePermission.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/connection/SocketPermission.hpp> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) ) 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir using namespace ::rtl; 42*cdf0e10cSrcweir using namespace ::osl; 43*cdf0e10cSrcweir using namespace ::com::sun::star; 44*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir namespace 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir inline OUString str_ac_singleton() 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir return OUSTR("/singletons/com.sun.star.security.theAccessController"); 51*cdf0e10cSrcweir } 52*cdf0e10cSrcweir } 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir namespace cppu 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir //__________________________________________________________________________________________________ 57*cdf0e10cSrcweir AccessControl::AccessControl( Reference< XComponentContext > const & xContext ) 58*cdf0e10cSrcweir SAL_THROW( (RuntimeException) ) 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir if (! (xContext->getValueByName( str_ac_singleton() ) >>= m_xController)) 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir throw SecurityException( 63*cdf0e10cSrcweir OUSTR("no access controller!"), Reference< XInterface >() ); 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir //__________________________________________________________________________________________________ 67*cdf0e10cSrcweir AccessControl::AccessControl( 68*cdf0e10cSrcweir Reference< security::XAccessController > const & xController ) 69*cdf0e10cSrcweir SAL_THROW( (RuntimeException) ) 70*cdf0e10cSrcweir : m_xController( xController ) 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir if (! m_xController.is()) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir throw SecurityException( 75*cdf0e10cSrcweir OUSTR("no access controller!"), Reference< XInterface >() ); 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir //__________________________________________________________________________________________________ 79*cdf0e10cSrcweir AccessControl::AccessControl( AccessControl const & ac ) 80*cdf0e10cSrcweir SAL_THROW( (RuntimeException) ) 81*cdf0e10cSrcweir : m_xController( ac.m_xController ) 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir if (! m_xController.is()) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir throw SecurityException( 86*cdf0e10cSrcweir OUSTR("no access controller!"), Reference< XInterface >() ); 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir #ifdef SAL_W32 91*cdf0e10cSrcweir #pragma pack(push, 8) 92*cdf0e10cSrcweir #endif 93*cdf0e10cSrcweir // binary comp. to all Permission structs 94*cdf0e10cSrcweir struct __permission 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir rtl_uString * m_str1; 97*cdf0e10cSrcweir rtl_uString * m_str2; 98*cdf0e10cSrcweir }; 99*cdf0e10cSrcweir #ifdef SAL_W32 100*cdf0e10cSrcweir #pragma pack(pop) 101*cdf0e10cSrcweir #endif 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir //-------------------------------------------------------------------------------------------------- 104*cdf0e10cSrcweir inline void __checkPermission( 105*cdf0e10cSrcweir Reference< security::XAccessController > const & xController, 106*cdf0e10cSrcweir Type const & type, rtl_uString * str1, rtl_uString * str2 ) 107*cdf0e10cSrcweir SAL_THROW( (RuntimeException) ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir __permission perm; 110*cdf0e10cSrcweir perm.m_str1 = str1; 111*cdf0e10cSrcweir perm.m_str2 = str2; 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir uno_Any a; 114*cdf0e10cSrcweir a.pType = type.getTypeLibType(); 115*cdf0e10cSrcweir a.pData = &perm; 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir xController->checkPermission( * static_cast< Any * >( &a ) ); 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir //__________________________________________________________________________________________________ 120*cdf0e10cSrcweir void AccessControl::checkRuntimePermission( 121*cdf0e10cSrcweir OUString const & name ) 122*cdf0e10cSrcweir SAL_THROW( (RuntimeException) ) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir __checkPermission( 125*cdf0e10cSrcweir m_xController, 126*cdf0e10cSrcweir ::getCppuType( (security::RuntimePermission *)0 ), name.pData, 0 ); 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir //__________________________________________________________________________________________________ 129*cdf0e10cSrcweir void AccessControl::checkFilePermission( 130*cdf0e10cSrcweir OUString const & url, 131*cdf0e10cSrcweir OUString const & actions ) 132*cdf0e10cSrcweir SAL_THROW( (RuntimeException) ) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir __checkPermission( 135*cdf0e10cSrcweir m_xController, 136*cdf0e10cSrcweir ::getCppuType( (io::FilePermission *)0 ), url.pData, actions.pData ); 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir //__________________________________________________________________________________________________ 139*cdf0e10cSrcweir void AccessControl::checkSocketPermission( 140*cdf0e10cSrcweir OUString const & host, 141*cdf0e10cSrcweir OUString const & actions ) 142*cdf0e10cSrcweir SAL_THROW( (RuntimeException) ) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir __checkPermission( 145*cdf0e10cSrcweir m_xController, 146*cdf0e10cSrcweir ::getCppuType( (connection::SocketPermission *)0 ), host.pData, actions.pData ); 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir } 150