LCOV - code coverage report
Current view: top level - cppuhelper/source - access_control.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 5 32 15.6 %
Date: 2015-06-13 12:38:46 Functions: 2 8 25.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             : using namespace ::osl;
      29             : using namespace ::com::sun::star;
      30             : using namespace ::com::sun::star::uno;
      31             : 
      32             : using rtl::OUString;
      33             : 
      34             : namespace
      35             : {
      36           1 :     inline OUString str_ac_singleton()
      37             :     {
      38           1 :         return OUString("/singletons/com.sun.star.security.theAccessController");
      39             :     }
      40             : }
      41             : 
      42             : namespace cppu
      43             : {
      44             : 
      45           1 : AccessControl::AccessControl( Reference< XComponentContext > const & xContext )
      46             : {
      47           1 :     if (! (xContext->getValueByName( str_ac_singleton() ) >>= m_xController))
      48             :     {
      49           0 :         throw SecurityException( "no access controller!" );
      50             :     }
      51           1 : }
      52             : 
      53           0 : AccessControl::AccessControl(
      54             :     Reference< security::XAccessController > const & xController )
      55           0 :     : m_xController( xController )
      56             : {
      57           0 :     if (! m_xController.is())
      58             :     {
      59           0 :         throw SecurityException( "no access controller!" );
      60             :     }
      61           0 : }
      62             : 
      63           0 : AccessControl::AccessControl( AccessControl const & ac )
      64           0 :     : m_xController( ac.m_xController )
      65             : {
      66           0 :     if (! m_xController.is())
      67             :     {
      68           0 :         throw SecurityException( "no access controller!" );
      69             :     }
      70           0 : }
      71             : 
      72             : #ifdef SAL_W32
      73             : #pragma pack(push, 8)
      74             : #endif
      75             :     // binary comp. to all Permission structs
      76             :     struct __permission
      77             :     {
      78             :         rtl_uString * m_str1;
      79             :         rtl_uString * m_str2;
      80             :     };
      81             : #ifdef SAL_W32
      82             : #pragma pack(pop)
      83             : #endif
      84             : 
      85             : 
      86           0 : inline void __checkPermission(
      87             :     Reference< security::XAccessController > const & xController,
      88             :     Type const & type, rtl_uString * str1, rtl_uString * str2 )
      89             : {
      90             :     __permission perm;
      91           0 :     perm.m_str1 = str1;
      92           0 :     perm.m_str2 = str2;
      93             : 
      94             :     uno_Any a;
      95           0 :     a.pType = type.getTypeLibType();
      96           0 :     a.pData = &perm;
      97             : 
      98           0 :     xController->checkPermission( * static_cast< Any * >( &a ) );
      99           0 : }
     100             : 
     101           0 : void AccessControl::checkRuntimePermission(
     102             :     OUString const & name )
     103             : {
     104             :     __checkPermission(
     105             :         m_xController,
     106           0 :         cppu::UnoType<security::RuntimePermission>::get(), name.pData, 0 );
     107           0 : }
     108             : 
     109           0 : void AccessControl::checkFilePermission(
     110             :     OUString const & url,
     111             :     OUString const & actions )
     112             : {
     113             :     __checkPermission(
     114             :         m_xController,
     115           0 :         cppu::UnoType<io::FilePermission>::get(), url.pData, actions.pData );
     116           0 : }
     117             : 
     118           0 : void AccessControl::checkSocketPermission(
     119             :     OUString const & host,
     120             :     OUString const & actions )
     121             : {
     122             :     __checkPermission(
     123             :         m_xController,
     124           0 :         cppu::UnoType<connection::SocketPermission>::get(), host.pData, actions.pData );
     125           0 : }
     126             : 
     127             : }
     128             : 
     129             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11