blob: b2c78cc34db71c91f56a7633891fc9f10bd69270 [file] [log] [blame]
Steven Moreland80e1e6d2019-06-21 12:35:59 -07001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <string>
20#include <sys/types.h>
21
22namespace android {
23
24// singleton
25class Access {
26public:
27 Access();
28 virtual ~Access();
29
30 Access(const Access&) = delete;
31 Access& operator=(const Access&) = delete;
32 Access(Access&&) = delete;
33 Access& operator=(Access&&) = delete;
34
35 struct CallingContext {
36 pid_t debugPid;
37 uid_t uid;
38 std::string sid;
39
40 // name of the service
41 //
42 // empty if call is unrelated to service (e.g. list)
43 std::string name;
44 };
45
46 virtual CallingContext getCallingContext(const std::string& name);
47
48 virtual bool canFind(const CallingContext& ctx);
49 virtual bool canAdd(const CallingContext& ctx);
50 virtual bool canList(const CallingContext& ctx);
51
52private:
53 bool actionAllowed(const CallingContext& sctx, const char* tctx, const char* perm);
54 bool actionAllowedFromLookup(const CallingContext& sctx, const char *perm);
55
56 char* mThisProcessContext = nullptr;
57};
58
59};