summaryrefslogtreecommitdiff
path: root/src/server/service/include/service.h
blob: 028a837beb12498aad354010cc42d0ccff2f50b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/*
 * Copyright (c) 2014-2022 Samsung Electronics Co., Ltd. All rights reserved.
 *
 * This file is licensed under the terms of MIT License or the Apache License
 * Version 2.0 of your choice. See the LICENSE.MIT file for MIT license details.
 * See the LICENSE file or the notice below for Apache License Version 2.0
 * details.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * @file        service.h
 * @author      Michal Witanowski <m.witanowski@samsung.com>
 * @author      Rafal Krypa <r.krypa@samsung.com>
 * @brief       Implementation of security-manager service
 */

#pragma once

#include <channel.h>
#include <credentials.h>
#include <message-buffer.h>
#include <service_impl.h>
#include <service-thread.h>
#include <socket-manager.h>

namespace SecurityManager {

struct Event {
    SocketManager::ConnectionID connectionID;
    Credentials creds;
    MessageBuffer buffer;
};

class Service final : public ServiceThread<Service, Event>
{
    ServiceImpl m_serviceImpl;
    SocketManager *m_serviceManager = nullptr;
public:
    static inline const SocketManager::ServiceDescription DESCRIPTION{
        SERVICE_SOCKET,  /* path */
        "*"              /* smackLabel label (not used, we rely on systemd) */
    };

    using Offline = ServiceImpl::Offline;
    explicit Service(Offline offline) : m_serviceImpl(offline) {}
    void RegisterChannel(Channel channel) {
        m_serviceImpl.RegisterChannel(std::move(channel));
    }

    void SetSocketManager(SocketManager *manager) {
        m_serviceManager = manager;
    }

    /**
     * Handle request from a client
     *
     * @param  conn Socket connection information
     * @param  msg  A message
     */
    void processEvent(Event &&msg);

private:

    /**
     * Process getting application manifest policy
     * @param buffer Input/output message buffer
     * @param creds  credentials of the requesting process
     */
    void processAppGetManifestPolicy(MessageBuffer &buffer, const Credentials &creds);

    /**
     * Process application installation
     *
     * @param buffer Input/output message buffer
     * @param creds  credentials of the requesting process
     */
    void processAppInstall(MessageBuffer &buffer, const Credentials &creds);

    /**
     * Process application update (currently only for cases when hybrid setting is changed)
     *
     * @param buffer Input/output message buffer
     * @param creds  credentials of the requesting process
     */
    void processAppUpdate(MessageBuffer &buffer, const Credentials &creds);

    /**
     * Process application uninstallation
     *
     * @param buffer Input/output message buffer
     * @param creds  credentials of the requesting process
     */
    void processAppUninstall(MessageBuffer &buffer, const Credentials &creds);

    /**
     * Process getting package identifier from an app identifier
     *
     * @param buffer Input/output message buffer
     */
    void processGetPkgName(MessageBuffer &buffer);

    void processUserAdd(MessageBuffer &buffer, const Credentials &creds);

    void processUserDelete(MessageBuffer &buffer, const Credentials &creds);

    /**
     * Process policy update request
     *
     * @param buffer Input/output message buffer
     * @param creds  credentials of the requesting process
     */
    void processPolicyUpdate(MessageBuffer &buffer, const Credentials &creds);

    /**
     * List all privileges for specific user, placed in Cynara's PRIVACY_MANAGER
     * or ADMIN's bucket - choice based on forAdmin parameter
     *
     * @param buffer   Input/output message buffer
     * @param creds    credentials of the requesting process
     * @param forAdmin determines internal type of request
     */
    void processGetConfiguredPolicy(MessageBuffer &buffer, const Credentials &creds, bool forAdmin);

    /**
     * Get whole policy for specific user. Whole policy is a list of all apps,
     * and their permissions (based on what they've stated in their manifests).
     *
     * If calling user is unprivileged, then only privileges for the caller uid
     * will be listed. If caller is privileged, then apps for all the users will
     * be listed.
     *
     * @param buffer Input/output message buffer
     * @param creds  credentials of the requesting process
     */
    void processGetPolicy(MessageBuffer &buffer, const Credentials &creds);

    /**
     * Process getting policies descriptions as strings from Cynara
     *
     * @param buffer Input/output message buffer
     */
    void processPolicyGetDesc(MessageBuffer &buffer);

    /**
     * Process getting groups bound with privileges and permitted group ids for app id
     *
     * @param buffer Input/output message buffer
     * @param creds  credentials of the requesting process
     */
    void processGetForbiddenAndAllowedGroups(MessageBuffer &buffer, const Credentials &creds);

    /**
     * Process getting groups bound with privileges for given uid
     *
     * @param buffer Output message buffer
     */
    void processGroupsForUid(MessageBuffer &buffer);

    /**
     * Process checking application's privilege access based on app_id
     *
     * @param buffer Input/output message buffer
     * @param creds  credentials of the requesting process
     */
    void processAppHasPrivilege(MessageBuffer &buffer, const Credentials &creds);

    /**
     * Process applying private path sharing between applications.
     *
     * @param buffer Input/output message buffer
     * @param creds  credentials of the requesting process
     */
    void processApplyPrivateSharing(MessageBuffer &buffer, const Credentials &creds);

    /**
     * Process drop private path sharing between applications.
     *
     * @param buffer Input/output message buffer
     * @param creds  credentials of the requesting process
     */
    void processDropPrivateSharing(MessageBuffer &buffer, const Credentials &creds);

    /**
     * Process package paths registration request
     *
     * @param buffer Input/output message buffer
     * @param creds  credentials of the requesting process
     */
    void processPathsRegister(MessageBuffer &buffer, const Credentials &creds);

    /**
     * Process shared memory access request
     *
     * @param buffer Input/output message buffer
     * @param creds  credentials of the requesting process
     */
    void processShmAppName(MessageBuffer &buffer, const Credentials &creds);

    /**
     * Process getting provider(app_id, pkg_id) of privilege
     *
     * @param buffer Input/output message buffer
     */
    void processGetAppDefinedPrivilegeProvider(MessageBuffer &buffer);

    /**
     * Process getting license of privilege
     *
     * @param buffer Input/output message buffer
     */
    void processGetAppDefinedPrivilegeLicense(MessageBuffer &buffer);

    /**
     * Process getting license of privilege
     *
     * @param buffer Input/output message buffer
     */
    void processGetClientPrivilegeLicense(MessageBuffer &buffer);

    /**
     * Process clean app namespace
     *
     * @param buffer Input/output message buffer
     * @param creds  credentials of the requesting process
     */
    void processAppCleanNamespace(MessageBuffer &buffer, const Credentials &creds);

    /**
     * Get process label
     *
     * @param buffer Input/output message buffer
     */
    void processGetProcessLabel(MessageBuffer &buffer);

    /**
     * Get app info (process label, package name, shared_ro flag) and groups, setup app namespace
     *
     * @param buffer Input/output message buffer
     * @param creds  credentials of the requesting process
     */
    void prepareApp(MessageBuffer &buffer, const Credentials &creds);
};

} // namespace SecurityManager