Mir
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 2 or 3 as
6  * 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 
17 #ifndef MIRAL_APPLICATION_AUTHORIZER_H
18 #define MIRAL_APPLICATION_AUTHORIZER_H
19 
20 #include <sys/types.h>
21 #include <functional>
22 #include <memory>
23 
24 namespace mir { class Server; }
25 namespace mir { namespace frontend { class SessionCredentials; } }
26 
27 namespace miral
28 {
30 {
31 public:
32  ApplicationCredentials(mir::frontend::SessionCredentials const& creds);
33 
34  pid_t pid() const;
35  uid_t uid() const;
36  gid_t gid() const;
37 
38 private:
39  ApplicationCredentials() = delete;
40 
41  mir::frontend::SessionCredentials const& creds;
42 };
43 
45 {
46 public:
47  ApplicationAuthorizer() = default;
48  virtual ~ApplicationAuthorizer() = default;
51 
52  virtual bool connection_is_allowed(ApplicationCredentials const& creds) = 0;
53  virtual bool configure_display_is_allowed(ApplicationCredentials const& creds) = 0;
55  virtual bool screencast_is_allowed(ApplicationCredentials const& creds) = 0;
56  virtual bool prompt_session_is_allowed(ApplicationCredentials const& creds) = 0;
57  virtual bool configure_input_is_allowed(ApplicationCredentials const& creds) = 0;
59 };
60 
62 {
63 public:
64  explicit BasicSetApplicationAuthorizer(std::function<std::shared_ptr<ApplicationAuthorizer>()> const& builder);
66 
67  void operator()(mir::Server& server);
68  auto the_application_authorizer() const -> std::shared_ptr<ApplicationAuthorizer>;
69 
70 private:
71  struct Self;
72  std::shared_ptr<Self> self;
73 };
74 
75 template<typename Policy>
77 {
78 public:
79  template<typename ...Args>
80  explicit SetApplicationAuthorizer(Args const& ...args) :
81  BasicSetApplicationAuthorizer{[&args...]() { return std::make_shared<Policy>(args...); }} {}
82 
83  auto the_custom_application_authorizer() const -> std::shared_ptr<Policy>
84  { return std::static_pointer_cast<Policy>(the_application_authorizer()); }
85 };
86 }
87 
88 #endif //MIRAL_APPLICATION_AUTHORIZER_H

Copyright © 2012-2022 Canonical Ltd.
Generated on Fri Aug 26 13:27:37 UTC 2022
This documentation is licensed under the GPL version 2 or 3.