LibreOffice Module cppuhelper (master) 1
access_control.cxx
Go to the documentation of this file.
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
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#include <com/sun/star/uno/XComponentContext.hpp>
28
29using namespace ::osl;
30using namespace ::com::sun::star;
31using namespace ::com::sun::star::uno;
32
33constexpr OUStringLiteral ACCESS_CONTROLLER_SINGLETON = u"/singletons/com.sun.star.security.theAccessController";
34
35namespace cppu
36{
37
38AccessControl::AccessControl( Reference< XComponentContext > const & xContext )
39{
40 if (! (xContext->getValueByName( ACCESS_CONTROLLER_SINGLETON ) >>= m_xController))
41 {
42 throw SecurityException( "no access controller!" );
43 }
44}
45
47 Reference< security::XAccessController > const & xController )
48 : m_xController( xController )
49{
50 if (! m_xController.is())
51 {
52 throw SecurityException( "no access controller!" );
53 }
54}
55
56AccessControl::AccessControl( AccessControl const & ac )
57 : m_xController( ac.m_xController )
58{
59 if (! m_xController.is())
60 {
61 throw SecurityException( "no access controller!" );
62 }
63}
64
65namespace {
66
67#ifdef _WIN32
68#pragma pack(push, 8)
69#endif
70 // binary comp. to all Permission structs
71 struct permission
72 {
73 rtl_uString * m_str1;
74 rtl_uString * m_str2;
75 };
76#ifdef _WIN32
77#pragma pack(pop)
78#endif
79
80void checkPermission(
81 Reference< security::XAccessController > const & xController,
82 Type const & type, rtl_uString * str1, rtl_uString * str2 )
83{
84 permission perm;
85 perm.m_str1 = str1;
86 perm.m_str2 = str2;
87
88 uno_Any a;
89 a.pType = type.getTypeLibType();
90 a.pData = &perm;
91
92 xController->checkPermission( * static_cast< Any * >( &a ) );
93}
94
95}
96
98 OUString const & name )
99{
100 checkPermission(
103}
104
106 OUString const & url,
107 OUString const & actions )
108{
109 checkPermission(
111 cppu::UnoType<io::FilePermission>::get(), url.pData, actions.pData );
112}
113
115 OUString const & host,
116 OUString const & actions )
117{
118 checkPermission(
120 cppu::UnoType<connection::SocketPermission>::get(), host.pData, actions.pData );
121}
122
123}
124
125/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
rtl_uString * m_str2
constexpr OUStringLiteral ACCESS_CONTROLLER_SINGLETON
rtl_uString * m_str1
void SAL_CALL checkFilePermission(::rtl::OUString const &url, ::rtl::OUString const &actions)
A com.sun.star.io.FilePermission represents access to a file or directory.
void SAL_CALL checkRuntimePermission(::rtl::OUString const &name)
A com.sun.star.security.RuntimePermission is for runtime permissions.
AccessControl(css::uno::Reference< css::uno::XComponentContext > const &xContext)
Ctor.
css::uno::Reference< css::security::XAccessController > m_xController
void SAL_CALL checkSocketPermission(::rtl::OUString const &host, ::rtl::OUString const &actions)
A com.sun.star.connection.SocketPermission represents access to a network via sockets.
float u
const char * name
uno_Any a
struct _uno_Any uno_Any
Type
Reference< XController > xController
ResultType type