Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 22 | namespace android { |
| 23 | |
| 24 | // singleton |
| 25 | class Access { |
| 26 | public: |
| 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; |
Steven Moreland | 5759db0 | 2024-03-27 00:03:05 +0000 | [diff] [blame] | 39 | |
| 40 | std::string toDebugString() const; |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
Steven Moreland | a9fe474 | 2019-07-18 14:45:20 -0700 | [diff] [blame] | 43 | virtual CallingContext getCallingContext(); |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 44 | |
Steven Moreland | a9fe474 | 2019-07-18 14:45:20 -0700 | [diff] [blame] | 45 | virtual bool canFind(const CallingContext& ctx, const std::string& name); |
| 46 | virtual bool canAdd(const CallingContext& ctx, const std::string& name); |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 47 | virtual bool canList(const CallingContext& ctx); |
| 48 | |
| 49 | private: |
Steven Moreland | 68039a1 | 2019-07-31 19:44:16 -0700 | [diff] [blame] | 50 | bool actionAllowed(const CallingContext& sctx, const char* tctx, const char* perm, |
| 51 | const std::string& tname); |
Steven Moreland | a9fe474 | 2019-07-18 14:45:20 -0700 | [diff] [blame] | 52 | bool actionAllowedFromLookup(const CallingContext& sctx, const std::string& name, |
| 53 | const char *perm); |
Steven Moreland | 80e1e6d | 2019-06-21 12:35:59 -0700 | [diff] [blame] | 54 | |
| 55 | char* mThisProcessContext = nullptr; |
| 56 | }; |
| 57 | |
| 58 | }; |