LCOV - code coverage report
Current view: top level - libreoffice/cppuhelper/source - access_control.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 32 0.0 %
Date: 2012-12-17 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      21             : #include <cppuhelper/access_control.hxx>
      22             : 
      23             : #include <com/sun/star/security/XAccessController.hpp>
      24             : #include <com/sun/star/security/RuntimePermission.hpp>
      25             : #include <com/sun/star/io/FilePermission.hpp>
      26             : #include <com/sun/star/connection/SocketPermission.hpp>
      27             : 
      28             : #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
      29             : 
      30             : 
      31             : using namespace ::rtl;
      32             : using namespace ::osl;
      33             : using namespace ::com::sun::star;
      34             : using namespace ::com::sun::star::uno;
      35             : 
      36             : namespace
      37             : {
      38           0 :     inline OUString str_ac_singleton()
      39             :     {
      40           0 :         return OUSTR("/singletons/com.sun.star.security.theAccessController");
      41             :     }
      42             : }
      43             : 
      44             : namespace cppu
      45             : {
      46             : //__________________________________________________________________________________________________
      47           0 : AccessControl::AccessControl( Reference< XComponentContext > const & xContext )
      48             :     SAL_THROW( (RuntimeException) )
      49             : {
      50           0 :     if (! (xContext->getValueByName( str_ac_singleton() ) >>= m_xController))
      51             :     {
      52             :         throw SecurityException(
      53           0 :             OUSTR("no access controller!"), Reference< XInterface >() );
      54             :     }
      55           0 : }
      56             : //__________________________________________________________________________________________________
      57           0 : AccessControl::AccessControl(
      58             :     Reference< security::XAccessController > const & xController )
      59             :     SAL_THROW( (RuntimeException) )
      60           0 :     : m_xController( xController )
      61             : {
      62           0 :     if (! m_xController.is())
      63             :     {
      64             :         throw SecurityException(
      65           0 :             OUSTR("no access controller!"), Reference< XInterface >() );
      66             :     }
      67           0 : }
      68             : //__________________________________________________________________________________________________
      69           0 : AccessControl::AccessControl( AccessControl const & ac )
      70             :     SAL_THROW( (RuntimeException) )
      71           0 :     : m_xController( ac.m_xController )
      72             : {
      73           0 :     if (! m_xController.is())
      74             :     {
      75             :         throw SecurityException(
      76           0 :             OUSTR("no access controller!"), Reference< XInterface >() );
      77             :     }
      78           0 : }
      79             : 
      80             : #ifdef SAL_W32
      81             : #pragma pack(push, 8)
      82             : #endif
      83             :     // binary comp. to all Permission structs
      84             :     struct __permission
      85             :     {
      86             :         rtl_uString * m_str1;
      87             :         rtl_uString * m_str2;
      88             :     };
      89             : #ifdef SAL_W32
      90             : #pragma pack(pop)
      91             : #endif
      92             : 
      93             : //--------------------------------------------------------------------------------------------------
      94           0 : inline void __checkPermission(
      95             :     Reference< security::XAccessController > const & xController,
      96             :     Type const & type, rtl_uString * str1, rtl_uString * str2 )
      97             :     SAL_THROW( (RuntimeException) )
      98             : {
      99             :     __permission perm;
     100           0 :     perm.m_str1 = str1;
     101           0 :     perm.m_str2 = str2;
     102             : 
     103             :     uno_Any a;
     104           0 :     a.pType = type.getTypeLibType();
     105           0 :     a.pData = &perm;
     106             : 
     107           0 :     xController->checkPermission( * static_cast< Any * >( &a ) );
     108           0 : }
     109             : //__________________________________________________________________________________________________
     110           0 : void AccessControl::checkRuntimePermission(
     111             :     OUString const & name )
     112             :     SAL_THROW( (RuntimeException) )
     113             : {
     114             :     __checkPermission(
     115             :         m_xController,
     116           0 :         ::getCppuType( (security::RuntimePermission *)0 ), name.pData, 0 );
     117           0 : }
     118             : //__________________________________________________________________________________________________
     119           0 : void AccessControl::checkFilePermission(
     120             :     OUString const & url,
     121             :     OUString const & actions )
     122             :     SAL_THROW( (RuntimeException) )
     123             : {
     124             :     __checkPermission(
     125             :         m_xController,
     126           0 :         ::getCppuType( (io::FilePermission *)0 ), url.pData, actions.pData );
     127           0 : }
     128             : //__________________________________________________________________________________________________
     129           0 : void AccessControl::checkSocketPermission(
     130             :     OUString const & host,
     131             :     OUString const & actions )
     132             :     SAL_THROW( (RuntimeException) )
     133             : {
     134             :     __checkPermission(
     135             :         m_xController,
     136           0 :         ::getCppuType( (connection::SocketPermission *)0 ), host.pData, actions.pData );
     137           0 : }
     138             : 
     139             : }
     140             : 
     141             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10