1 /*
2  * Copyright (C) 2016 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 #ifndef KEYSTORE_PERMISSIONS_H_
18 #define KEYSTORE_PERMISSIONS_H_
19 
20 #include <unistd.h>
21 
22 /* Here are the permissions, actions, users, and the main function. */
23 enum perm_t {
24     P_GET_STATE = 1 << 0,
25     P_GET = 1 << 1,
26     P_INSERT = 1 << 2,
27     P_DELETE = 1 << 3,
28     P_EXIST = 1 << 4,
29     P_LIST = 1 << 5,
30     P_RESET = 1 << 6,
31     P_PASSWORD = 1 << 7,
32     P_LOCK = 1 << 8,
33     P_UNLOCK = 1 << 9,
34     P_IS_EMPTY = 1 << 10,
35     P_SIGN = 1 << 11,
36     P_VERIFY = 1 << 12,
37     P_GRANT = 1 << 13,
38     P_DUPLICATE = 1 << 14,
39     P_CLEAR_UID = 1 << 15,
40     P_ADD_AUTH = 1 << 16,
41     P_USER_CHANGED = 1 << 17,
42     P_GEN_UNIQUE_ID = 1 << 18,
43 };
44 
45 const char* get_perm_label(perm_t perm);
46 
47 /**
48  * Returns the UID that the callingUid should act as. This is here for
49  * legacy support of the WiFi and VPN systems and should be removed
50  * when WiFi can operate in its own namespace.
51  */
52 uid_t get_keystore_euid(uid_t uid);
53 
54 bool has_permission(uid_t uid, perm_t perm, pid_t spid);
55 
56 /**
57  * Returns true if the callingUid is allowed to interact in the targetUid's
58  * namespace.
59  */
60 bool is_granted_to(uid_t callingUid, uid_t targetUid);
61 
62 int configure_selinux();
63 
64 #endif  // KEYSTORE_PERMISSIONS_H_
65