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