1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef XTS_ACTS_SECURITY_LITE_PERMISSSION_POSIX_CAPABILITY_SRC_ACTSCAPABILITYTEST_H 16 #define XTS_ACTS_SECURITY_LITE_PERMISSSION_POSIX_CAPABILITY_SRC_ACTSCAPABILITYTEST_H 17 18 #include <cstddef> 19 #include <sys/stat.h> 20 21 constexpr int FALSE = -1; 22 constexpr int NUM0 = 0; 23 constexpr int NUM1 = 1; 24 constexpr int NUM2 = 2; 25 constexpr int NUM3 = 3; 26 constexpr int NUM5 = 5; 27 constexpr int NUM20 = 20; 28 constexpr int NUM80 = 80; 29 constexpr int NUM100 = 100; 30 constexpr int NUM500 = 500; 31 constexpr int NUM600 = 600; 32 constexpr int NUM700 = 700; 33 constexpr int NUM1000 = 1000; 34 constexpr int NUM3000 = 3000; 35 constexpr int NUM5000 = 5000; 36 constexpr int NUM10000 = 10000; 37 38 constexpr int INIT_PID = 1; 39 constexpr int KPROCESS_PID = 2; 40 constexpr int SHELL_PID = 8; 41 constexpr int HILOGCAT_PID = 10; 42 constexpr int FOUNDATION_PID = 3; 43 constexpr int BUNDLE_DAEMON_PID = 4; 44 constexpr int APPSPAWN_PID = 5; 45 constexpr int MEDIA_SERVER_PID = 6; 46 constexpr int WMS_SERVER_OR_AI_SERVER_PID = 7; 47 constexpr int HIVIEW_PID = 10; 48 constexpr int OTHER_PID = 12; 49 constexpr int INIT_PID_2 = 1; 50 constexpr int KPROCESS_PID_2 = 2; 51 constexpr int SHELL_PID_2 = 8; 52 constexpr int HILOGCAT_PID_2 = 10; 53 constexpr int FOUNDATION_PID_2 = 3; 54 constexpr int BUNDLE_DAEMON_PID_2 = 4; 55 constexpr int APPSPAWN_PID_2 = 5; 56 constexpr int MEDIA_SERVER_PID_2 = 6; 57 constexpr int WMS_SERVER_OR_AI_SERVER_PID_2 = 7; 58 constexpr int HIVIEW_PID_2 = 10; 59 constexpr int OTHER_PID_2 = 12; 60 61 constexpr unsigned int INIT_CAP = 0x02e83def; 62 constexpr unsigned int KPROCESS_CAP = 0x02e83def; 63 constexpr unsigned int SHELL_CAP = 0x02e83def; 64 constexpr unsigned int HILOGCAT_CAP = 0x00000000; 65 constexpr unsigned int FOUNDATION_CAP = 0x00003c00; 66 constexpr unsigned int BUNDLE_DAEMON_CAP = 0x00000007; 67 constexpr unsigned int APPSPAWN_CAP = 0x008009c4; 68 constexpr unsigned int MEDIA_SERVER_CAP = 0x00000000; 69 constexpr unsigned int WMS_SERVER_OR_AI_SERVER_CAP = 0x00000000; 70 constexpr unsigned int HIVIEW_CAP = 0x00000000; 71 constexpr unsigned int LINUX_FULL_CAP = 0xffffffff; 72 constexpr unsigned int OHOS_FULL_CAP = 0x02e83def; 73 constexpr unsigned int NO_CAP = 0x00000000; 74 constexpr unsigned int ONLY_SETPCAP_CAP = 0x00000100; 75 76 constexpr int CAP_NUM = 2; 77 constexpr int INVALID_CAP_TO_INDEX = 40; 78 constexpr int MAX_PATH_SIZE = 256; 79 constexpr int INVAILD_PID = 65536; 80 constexpr int SLEEP_NUM = 100000; 81 constexpr int LONG_SLEEP_NUM = 2000000; 82 constexpr int PID_MAX = 4194305; 83 84 constexpr mode_t ZERO = 0000; 85 constexpr mode_t NORWX = 0001; 86 constexpr mode_t RWX = 0777; 87 88 constexpr uid_t UID0 = 0; 89 constexpr uid_t UID1 = 1; 90 constexpr uid_t UID555 = 555; 91 constexpr uid_t UID1000 = 1000; 92 constexpr uid_t UID10000 = 10000; 93 constexpr uid_t UID20000 = 20000; 94 constexpr gid_t GID0 = 0; 95 constexpr gid_t GID1 = 1; 96 constexpr gid_t GID555 = 555; 97 constexpr gid_t GID1000 = 1000; 98 constexpr gid_t GID10000 = 10000; 99 constexpr gid_t GID20000 = 20000; 100 constexpr gid_t GROUPLIST[NUM3] = { 500, 500, 500 }; 101 102 constexpr size_t SIZE512 = 512; 103 104 // Creating Folders and Files for the Test 105 #define CAPDIR0 "CAPDIR0" // DIR0/ 106 #define CAPDIR0_CAPFILE0 "CAPDIR0_CAPFILE0" // ├── DIR0_FILE0 107 #define CAPDIR0_CAPFILE1 "CAPDIR0_CAPFILE1" // ├── DIR0_FILE1 108 #define CAPDIR0_CAPDIR0 "CAPDIR0_CAPDIR0" // ├── DIR0_DIR0/ 109 #define CAPDIR0_CAPDIR1 "CAPDIR0_CAPDIR1" // └── DIR0_DIR1/ 110 111 extern "C" { 112 #define LOG(format, ...) printf("%s:%d:\n" format "\n", __FILE__, __LINE__, ##__VA_ARGS__); 113 } 114 115 void Sigac(int i); 116 117 void ChildSleep(); 118 119 int CapInit(); 120 121 int DropCAPCHOWN(); 122 123 int DropCAPDACOVERRIDE(); 124 125 int DropCAPDACREADSEARCH(); 126 127 int DropCAPDACOVERRIDEAndREADSEARCH(); 128 129 int DropCAPFOWNER(); 130 131 int DropCAPKILL(); 132 133 int DropCAPSETGID(); 134 135 int DropCAPSETUID(); 136 137 int DropCAPSETPCAP(); 138 139 int DropCAPSYSNICE(); 140 141 int DropCAPSYSTIME(); 142 143 int DropAllCAP(); 144 145 int RemoveDir(const char *dirname); 146 147 int SetUidGid(uid_t uid, gid_t gid); 148 149 timespec CompareTime(timespec start, timespec end); 150 151 char *GetCurrentPath(); 152 153 int CheckFsMount(const char *topDir, const char *topDirMountInfo); 154 155 #endif 156