2010-10-14 01:30:07 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2001-12-14 06:19:51 -06:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 05:31:32 -05:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2001-12-14 06:19:51 -06:00
|
|
|
*
|
2010-02-12 08:01:35 -06:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2001-12-14 06:19:51 -06:00
|
|
|
*
|
2008-04-11 05:31:32 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2001-12-14 06:19:51 -06:00
|
|
|
*
|
2008-04-11 05:31:32 -05:00
|
|
|
* This file is part of OpenOffice.org.
|
2001-12-14 06:19:51 -06:00
|
|
|
*
|
2008-04-11 05:31:32 -05:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2001-12-14 06:19:51 -06:00
|
|
|
*
|
2008-04-11 05:31:32 -05:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2001-12-14 06:19:51 -06:00
|
|
|
*
|
2008-04-11 05:31:32 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2001-12-14 06:19:51 -06:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-16 06:39:07 -05:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_cppuhelper.hxx"
|
|
|
|
|
2002-01-11 03:06:02 -06:00
|
|
|
#include <cppuhelper/access_control.hxx>
|
2001-12-14 06:19:51 -06:00
|
|
|
|
|
|
|
#include <com/sun/star/security/XAccessController.hpp>
|
2002-01-11 03:06:02 -06:00
|
|
|
#include <com/sun/star/security/RuntimePermission.hpp>
|
|
|
|
#include <com/sun/star/io/FilePermission.hpp>
|
|
|
|
#include <com/sun/star/connection/SocketPermission.hpp>
|
|
|
|
|
2001-12-14 06:19:51 -06:00
|
|
|
#define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
|
|
|
|
|
|
|
|
|
|
|
|
using namespace ::rtl;
|
|
|
|
using namespace ::osl;
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
|
2004-06-25 11:37:31 -05:00
|
|
|
namespace
|
2001-12-14 06:19:51 -06:00
|
|
|
{
|
2004-06-25 11:37:31 -05:00
|
|
|
inline OUString str_ac_singleton()
|
|
|
|
{
|
|
|
|
return OUSTR("/singletons/com.sun.star.security.theAccessController");
|
|
|
|
}
|
|
|
|
}
|
2001-12-14 06:19:51 -06:00
|
|
|
|
2004-06-25 11:37:31 -05:00
|
|
|
namespace cppu
|
|
|
|
{
|
2002-01-11 03:06:02 -06:00
|
|
|
//__________________________________________________________________________________________________
|
|
|
|
AccessControl::AccessControl( Reference< XComponentContext > const & xContext )
|
|
|
|
SAL_THROW( (RuntimeException) )
|
|
|
|
{
|
2004-06-25 11:37:31 -05:00
|
|
|
if (! (xContext->getValueByName( str_ac_singleton() ) >>= m_xController))
|
2002-01-11 03:06:02 -06:00
|
|
|
{
|
|
|
|
throw SecurityException(
|
|
|
|
OUSTR("no access controller!"), Reference< XInterface >() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//__________________________________________________________________________________________________
|
|
|
|
AccessControl::AccessControl(
|
|
|
|
Reference< security::XAccessController > const & xController )
|
|
|
|
SAL_THROW( (RuntimeException) )
|
|
|
|
: m_xController( xController )
|
|
|
|
{
|
|
|
|
if (! m_xController.is())
|
|
|
|
{
|
|
|
|
throw SecurityException(
|
|
|
|
OUSTR("no access controller!"), Reference< XInterface >() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//__________________________________________________________________________________________________
|
|
|
|
AccessControl::AccessControl( AccessControl const & ac )
|
|
|
|
SAL_THROW( (RuntimeException) )
|
|
|
|
: m_xController( ac.m_xController )
|
|
|
|
{
|
|
|
|
if (! m_xController.is())
|
|
|
|
{
|
|
|
|
throw SecurityException(
|
|
|
|
OUSTR("no access controller!"), Reference< XInterface >() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SAL_W32
|
|
|
|
#pragma pack(push, 8)
|
|
|
|
#endif
|
|
|
|
// binary comp. to all Permission structs
|
|
|
|
struct __permission
|
|
|
|
{
|
|
|
|
rtl_uString * m_str1;
|
|
|
|
rtl_uString * m_str2;
|
|
|
|
};
|
|
|
|
#ifdef SAL_W32
|
|
|
|
#pragma pack(pop)
|
|
|
|
#endif
|
|
|
|
|
2001-12-14 06:19:51 -06:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2002-01-11 03:15:50 -06:00
|
|
|
inline void __checkPermission(
|
2002-01-11 03:06:02 -06:00
|
|
|
Reference< security::XAccessController > const & xController,
|
|
|
|
Type const & type, rtl_uString * str1, rtl_uString * str2 )
|
|
|
|
SAL_THROW( (RuntimeException) )
|
|
|
|
{
|
|
|
|
__permission perm;
|
|
|
|
perm.m_str1 = str1;
|
|
|
|
perm.m_str2 = str2;
|
|
|
|
|
|
|
|
uno_Any a;
|
|
|
|
a.pType = type.getTypeLibType();
|
|
|
|
a.pData = &perm;
|
|
|
|
|
2006-06-19 04:32:19 -05:00
|
|
|
xController->checkPermission( * static_cast< Any * >( &a ) );
|
2002-01-11 03:06:02 -06:00
|
|
|
}
|
|
|
|
//__________________________________________________________________________________________________
|
|
|
|
void AccessControl::checkRuntimePermission(
|
|
|
|
OUString const & name )
|
|
|
|
SAL_THROW( (RuntimeException) )
|
2001-12-14 06:19:51 -06:00
|
|
|
{
|
2002-01-11 03:06:02 -06:00
|
|
|
__checkPermission(
|
|
|
|
m_xController,
|
|
|
|
::getCppuType( (security::RuntimePermission *)0 ), name.pData, 0 );
|
2001-12-14 06:19:51 -06:00
|
|
|
}
|
2002-01-11 03:06:02 -06:00
|
|
|
//__________________________________________________________________________________________________
|
|
|
|
void AccessControl::checkFilePermission(
|
|
|
|
OUString const & url,
|
|
|
|
OUString const & actions )
|
|
|
|
SAL_THROW( (RuntimeException) )
|
|
|
|
{
|
|
|
|
__checkPermission(
|
|
|
|
m_xController,
|
|
|
|
::getCppuType( (io::FilePermission *)0 ), url.pData, actions.pData );
|
|
|
|
}
|
|
|
|
//__________________________________________________________________________________________________
|
|
|
|
void AccessControl::checkSocketPermission(
|
|
|
|
OUString const & host,
|
|
|
|
OUString const & actions )
|
|
|
|
SAL_THROW( (RuntimeException) )
|
2001-12-14 06:19:51 -06:00
|
|
|
{
|
2002-01-11 03:06:02 -06:00
|
|
|
__checkPermission(
|
|
|
|
m_xController,
|
|
|
|
::getCppuType( (connection::SocketPermission *)0 ), host.pData, actions.pData );
|
2001-12-14 06:19:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2010-10-14 01:30:07 -05:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|