~alan-griffiths/mir/migrate-tests-to-miral

« back to all changes in this revision

Viewing changes to include/miral/miral/application_authorizer.h

  • Committer: Christopher James Halse Rogers
  • Date: 2017-09-07 05:58:13 UTC
  • mfrom: (4242 development-branch)
  • mto: (4243.1.1 mir3)
  • mto: This revision was merged to the branch mainline in revision 4244.
  • Revision ID: christopher.halse.rogers@canonical.com-20170907055813-4qsg25nirybc8jj3
Merge trunk, resolving conflict

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 * 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 <functional>
 
26
#include <memory>
 
27
 
 
28
namespace mir { class Server; }
 
29
namespace mir { namespace frontend { class SessionCredentials; } }
 
30
 
 
31
namespace miral
 
32
{
 
33
class ApplicationCredentials
 
34
{
 
35
public:
 
36
    ApplicationCredentials(mir::frontend::SessionCredentials const& creds);
 
37
 
 
38
    pid_t pid() const;
 
39
    uid_t uid() const;
 
40
    gid_t gid() const;
 
41
 
 
42
private:
 
43
    ApplicationCredentials() = delete;
 
44
 
 
45
    mir::frontend::SessionCredentials const& creds;
 
46
};
 
47
 
 
48
class ApplicationAuthorizer
 
49
{
 
50
public:
 
51
    ApplicationAuthorizer() = default;
 
52
    virtual ~ApplicationAuthorizer() = default;
 
53
    ApplicationAuthorizer(ApplicationAuthorizer const&) = delete;
 
54
    ApplicationAuthorizer& operator=(ApplicationAuthorizer const&) = delete;
 
55
 
 
56
    virtual bool connection_is_allowed(ApplicationCredentials const& creds) = 0;
 
57
    virtual bool configure_display_is_allowed(ApplicationCredentials const& creds) = 0;
 
58
    virtual bool set_base_display_configuration_is_allowed(ApplicationCredentials const& creds) = 0;
 
59
    virtual bool screencast_is_allowed(ApplicationCredentials const& creds) = 0;
 
60
    virtual bool prompt_session_is_allowed(ApplicationCredentials const& creds) = 0;
 
61
};
 
62
 
 
63
// Mir has introduced new functions. We can't introduce new functions to ApplicationAuthorizer
 
64
// without breaking ABI, but we can offer an extension interface:
 
65
class ApplicationAuthorizer1 : public ApplicationAuthorizer
 
66
{
 
67
public:
 
68
    virtual bool configure_input_is_allowed(ApplicationCredentials const& creds) = 0;
 
69
    virtual bool set_base_input_configuration_is_allowed(ApplicationCredentials const& creds) = 0;
 
70
 
 
71
#if MIRAL_VERSION >= MIR_VERSION_NUMBER(2, 0, 0)
 
72
#error "We've presumably broken ABI - please roll this interface into ApplicationAuthorizer"
 
73
#endif
 
74
};
 
75
 
 
76
class BasicSetApplicationAuthorizer
 
77
{
 
78
public:
 
79
    explicit BasicSetApplicationAuthorizer(std::function<std::shared_ptr<ApplicationAuthorizer>()> const& builder);
 
80
    ~BasicSetApplicationAuthorizer();
 
81
 
 
82
    void operator()(mir::Server& server);
 
83
    auto the_application_authorizer() const -> std::shared_ptr<ApplicationAuthorizer>;
 
84
 
 
85
private:
 
86
    struct Self;
 
87
    std::shared_ptr<Self> self;
 
88
};
 
89
 
 
90
template<typename Policy>
 
91
class SetApplicationAuthorizer : public BasicSetApplicationAuthorizer
 
92
{
 
93
public:
 
94
    template<typename ...Args>
 
95
    explicit SetApplicationAuthorizer(Args const& ...args) :
 
96
        BasicSetApplicationAuthorizer{[&args...]() { return std::make_shared<Policy>(args...); }} {}
 
97
 
 
98
    auto the_custom_application_authorizer() const -> std::shared_ptr<Policy>
 
99
        { return std::static_pointer_cast<Policy>(the_application_authorizer()); }
 
100
};
 
101
}
 
102
 
 
103
#endif //MIRAL_APPLICATION_AUTHORIZER_H