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 0 : inline OUString str_ac_singleton()
37 : {
38 0 : return OUString("/singletons/com.sun.star.security.theAccessController");
39 : }
40 : }
41 :
42 : namespace cppu
43 : {
44 :
45 0 : AccessControl::AccessControl( Reference< XComponentContext > const & xContext )
46 : SAL_THROW( (RuntimeException) )
47 : {
48 0 : if (! (xContext->getValueByName( str_ac_singleton() ) >>= m_xController))
49 : {
50 : throw SecurityException(
51 0 : "no access controller!", Reference< XInterface >() );
52 : }
53 0 : }
54 :
55 0 : AccessControl::AccessControl(
56 : Reference< security::XAccessController > const & xController )
57 : SAL_THROW( (RuntimeException) )
58 0 : : m_xController( xController )
59 : {
60 0 : if (! m_xController.is())
61 : {
62 : throw SecurityException(
63 0 : "no access controller!", Reference< XInterface >() );
64 : }
65 0 : }
66 :
67 0 : AccessControl::AccessControl( AccessControl const & ac )
68 : SAL_THROW( (RuntimeException) )
69 0 : : m_xController( ac.m_xController )
70 : {
71 0 : if (! m_xController.is())
72 : {
73 : throw SecurityException(
74 0 : "no access controller!", Reference< XInterface >() );
75 : }
76 0 : }
77 :
78 : #ifdef SAL_W32
79 : #pragma pack(push, 8)
80 : #endif
81 : // binary comp. to all Permission structs
82 : struct __permission
83 : {
84 : rtl_uString * m_str1;
85 : rtl_uString * m_str2;
86 : };
87 : #ifdef SAL_W32
88 : #pragma pack(pop)
89 : #endif
90 :
91 :
92 0 : inline void __checkPermission(
93 : Reference< security::XAccessController > const & xController,
94 : Type const & type, rtl_uString * str1, rtl_uString * str2 )
95 : SAL_THROW( (RuntimeException) )
96 : {
97 : __permission perm;
98 0 : perm.m_str1 = str1;
99 0 : perm.m_str2 = str2;
100 :
101 : uno_Any a;
102 0 : a.pType = type.getTypeLibType();
103 0 : a.pData = &perm;
104 :
105 0 : xController->checkPermission( * static_cast< Any * >( &a ) );
106 0 : }
107 :
108 0 : void AccessControl::checkRuntimePermission(
109 : OUString const & name )
110 : SAL_THROW( (RuntimeException) )
111 : {
112 : __checkPermission(
113 : m_xController,
114 0 : ::getCppuType( (security::RuntimePermission *)0 ), name.pData, 0 );
115 0 : }
116 :
117 0 : void AccessControl::checkFilePermission(
118 : OUString const & url,
119 : OUString const & actions )
120 : SAL_THROW( (RuntimeException) )
121 : {
122 : __checkPermission(
123 : m_xController,
124 0 : ::getCppuType( (io::FilePermission *)0 ), url.pData, actions.pData );
125 0 : }
126 :
127 0 : void AccessControl::checkSocketPermission(
128 : OUString const & host,
129 : OUString const & actions )
130 : SAL_THROW( (RuntimeException) )
131 : {
132 : __checkPermission(
133 : m_xController,
134 0 : ::getCppuType( (connection::SocketPermission *)0 ), host.pData, actions.pData );
135 0 : }
136 :
137 : }
138 :
139 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|