MirAL
application_authorizer.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2016 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Alan Griffiths <alan@octopull.co.uk>
17  */
18 
19 #ifndef MIRAL_APPLICATION_AUTHORIZER_H
20 #define MIRAL_APPLICATION_AUTHORIZER_H
21 
22 #include <miral/version.h>
23 
24 #include <sys/types.h>
25 #include <memory>
26 
27 namespace mir { class Server; }
28 namespace mir { namespace frontend { class SessionCredentials; } }
29 
30 namespace miral
31 {
33 {
34 public:
35  ApplicationCredentials(mir::frontend::SessionCredentials const& creds);
36 
37  pid_t pid() const;
38  uid_t uid() const;
39  gid_t gid() const;
40 
41 private:
42  ApplicationCredentials() = delete;
43 
44  mir::frontend::SessionCredentials const& creds;
45 };
46 
48 {
49 public:
50  ApplicationAuthorizer() = default;
51  virtual ~ApplicationAuthorizer() = default;
53  ApplicationAuthorizer& operator=(ApplicationAuthorizer const&) = delete;
54 
55  virtual bool connection_is_allowed(ApplicationCredentials const& creds) = 0;
56  virtual bool configure_display_is_allowed(ApplicationCredentials const& creds) = 0;
57  virtual bool set_base_display_configuration_is_allowed(ApplicationCredentials const& creds) = 0;
58  virtual bool screencast_is_allowed(ApplicationCredentials const& creds) = 0;
59  virtual bool prompt_session_is_allowed(ApplicationCredentials const& creds) = 0;
60 };
61 
62 // Mir has introduced new functions. We can't introduce new functions to ApplicationAuthorizer
63 // without breaking ABI, but we can offer an extension interface:
65 {
66 public:
67  virtual bool configure_input_is_allowed(ApplicationCredentials const& creds) = 0;
68  virtual bool set_base_input_configuration_is_allowed(ApplicationCredentials const& creds) = 0;
69 
70 #if MIRAL_VERSION >= MIR_VERSION_NUMBER(2, 0, 0)
71 #error "We've presumably broken ABI - please roll this interface into ApplicationAuthorizer"
72 #endif
73 };
74 
76 {
77 public:
78  explicit BasicSetApplicationAuthorizer(std::function<std::shared_ptr<ApplicationAuthorizer>()> const& builder);
80 
81  void operator()(mir::Server& server);
82  auto the_application_authorizer() const -> std::shared_ptr<ApplicationAuthorizer>;
83 
84 private:
85  struct Self;
86  std::shared_ptr<Self> self;
87 };
88 
89 template<typename Policy>
91 {
92 public:
93  template<typename ...Args>
94  explicit SetApplicationAuthorizer(Args const& ...args) :
95  BasicSetApplicationAuthorizer{[&args...]() { return std::make_shared<Policy>(args...); }} {}
96 
97  auto the_custom_application_authorizer() const -> std::shared_ptr<Policy>
98  { return std::static_pointer_cast<Policy>(the_application_authorizer()); }
99 };
100 }
101 
102 #endif //MIRAL_APPLICATION_AUTHORIZER_H
Definition: blob.h:26
Definition: application_authorizer.h:47
STL namespace.
auto the_custom_application_authorizer() const -> std::shared_ptr< Policy >
Definition: application_authorizer.h:97
SetApplicationAuthorizer(Args const &...args)
Definition: application_authorizer.h:94
Definition: application_authorizer.h:64
Definition: application_authorizer.h:75
Definition: application_authorizer.h:90
Definition: application_authorizer.h:32
Mir Abstraction Layer.
Definition: active_outputs.h:27

Copyright © 2016 Canonical Ltd.
Generated on Thu Mar 30 14:25:04 UTC 2017