Remove exec bits from docx
[LibreOffice.git] / cppuhelper / source / access_control.cxx
blobda8343648a954ae43e98462bc9e4eba5838fa7ed
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <cppuhelper/access_control.hxx>
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>
29 using namespace ::osl;
30 using namespace ::com::sun::star;
31 using namespace ::com::sun::star::uno;
33 constexpr OUStringLiteral ACCESS_CONTROLLER_SINGLETON = u"/singletons/com.sun.star.security.theAccessController";
35 namespace cppu
38 AccessControl::AccessControl( Reference< XComponentContext > const & xContext )
40 if (! (xContext->getValueByName( ACCESS_CONTROLLER_SINGLETON ) >>= m_xController))
42 throw SecurityException( "no access controller!" );
46 AccessControl::AccessControl(
47 Reference< security::XAccessController > const & xController )
48 : m_xController( xController )
50 if (! m_xController.is())
52 throw SecurityException( "no access controller!" );
56 AccessControl::AccessControl( AccessControl const & ac )
57 : m_xController( ac.m_xController )
59 if (! m_xController.is())
61 throw SecurityException( "no access controller!" );
65 namespace {
67 #ifdef _WIN32
68 #pragma pack(push, 8)
69 #endif
70 // binary comp. to all Permission structs
71 struct permission
73 rtl_uString * m_str1;
74 rtl_uString * m_str2;
76 #ifdef _WIN32
77 #pragma pack(pop)
78 #endif
80 void checkPermission(
81 Reference< security::XAccessController > const & xController,
82 Type const & type, rtl_uString * str1, rtl_uString * str2 )
84 permission perm;
85 perm.m_str1 = str1;
86 perm.m_str2 = str2;
88 uno_Any a;
89 a.pType = type.getTypeLibType();
90 a.pData = &perm;
92 xController->checkPermission( * static_cast< Any * >( &a ) );
97 void AccessControl::checkRuntimePermission(
98 OUString const & name )
100 checkPermission(
101 m_xController,
102 cppu::UnoType<security::RuntimePermission>::get(), name.pData, nullptr );
105 void AccessControl::checkFilePermission(
106 OUString const & url,
107 OUString const & actions )
109 checkPermission(
110 m_xController,
111 cppu::UnoType<io::FilePermission>::get(), url.pData, actions.pData );
114 void AccessControl::checkSocketPermission(
115 OUString const & host,
116 OUString const & actions )
118 checkPermission(
119 m_xController,
120 cppu::UnoType<connection::SocketPermission>::get(), host.pData, actions.pData );
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */