1/* 2 * Copyright (c) 2024 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 16#include "app_spawn_stub.h" 17 18#include <cerrno> 19#include <csignal> 20#include <cstdarg> 21#include <cstdbool> 22#include <cstdlib> 23#include <ctime> 24#include <fcntl.h> 25#include <pthread.h> 26#include <pwd.h> 27#include <grp.h> 28 29#include <linux/capability.h> 30#include <sys/socket.h> 31#include <sys/stat.h> 32#include <sys/time.h> 33#include <sys/types.h> 34#include <sys/un.h> 35#include <sys/wait.h> 36#include <unistd.h> 37 38#include "access_token.h" 39#include "hilog/log.h" 40#include "securec.h" 41#include "token_setproc.h" 42#include "tokenid_kit.h" 43 44#ifdef WITH_SELINUX 45#include "hap_restorecon.h" 46#endif 47#ifdef WITH_SECCOMP 48#include "seccomp_policy.h" 49#include <sys/prctl.h> 50#endif 51 52namespace OHOS { 53namespace system { 54 bool GetIntParameter(const std::string &key, bool def, bool arg1 = false, bool arg2 = false) 55 { 56 return def; 57 } 58 59 bool GetBoolParameter(const std::string &key, bool def) 60 { 61 return def; 62 } 63} // namespace system 64 65namespace Security { 66 namespace AccessToken { 67 uint64_t TokenIdKit::GetRenderTokenID(uint64_t tokenId) 68 { 69 return tokenId; 70 } 71 } // namespace AccessToken 72} // namespace Security 73} // namespace OHOS 74 75#ifdef WITH_SELINUX 76HapContext::HapContext() {} 77HapContext::~HapContext() {} 78int HapContext::HapDomainSetcontext(HapDomainInfo &hapDomainInfo) 79{ 80 return 0; 81} 82#endif 83 84#ifdef __cplusplus 85extern "C" { 86#endif 87void ResetParamSecurityLabel() {} 88 89int SetSelfTokenID(uint64_t tokenId) 90{ 91 return 0; 92} 93 94void SetTraceDisabled(int disable) {} 95 96#ifdef WITH_SECCOMP 97bool SetSeccompPolicyWithName(SeccompFilterType filter, const char *filterName) 98{ 99 static int result = 0; 100 result++; 101 return true; // (result % 3) == 0; // 3 is test data 102} 103 104bool IsEnableSeccomp(void) 105{ 106 return true; 107} 108#endif 109 110int GetControlSocket(const char *name) 111{ 112 return -1; 113} 114 115static bool g_developerMode = true; 116void SetDeveloperMode(bool mode) 117{ 118 g_developerMode = mode; 119} 120 121int GetParameter(const char *key, const char *def, char *value, uint32_t len) 122{ 123 static uint32_t count = 0; 124 count++; 125 if (strcmp(key, "startup.appspawn.cold.boot") == 0) { 126 return strcpy_s(value, len, "true") == 0 ? strlen("true") : -1; 127 } 128 if (strcmp(key, "persist.appspawn.reqMgr.timeout") == 0) { 129 const char *tmp = def; 130 if ((count % 3) == 0) { // 3 test 131 return -1; 132 } else if ((count % 3) == 1) { // 3 test 133 tmp = "a"; 134 } else { 135 tmp = "5"; 136 } 137 return strcpy_s(value, len, tmp) == 0 ? strlen(tmp) : -1; 138 } 139 if (strcmp(key, "const.security.developermode.state") == 0) { 140 return g_developerMode ? (strcpy_s(value, len, "true") == 0 ? strlen("true") : -1) : -1; 141 } 142 if (strcmp(key, "persist.nweb.sandbox.src_path") == 0) { 143 return strcpy_s(value, len, def) == 0 ? strlen(def) : -1; 144 } 145 if (strcmp(key, "test.variable.001") == 0) { 146 return strcpy_s(value, len, "test.variable.001") == 0 ? strlen("test.variable.001") : -1; 147 } 148 if (strcmp(key, "persist.arkwebcore.package_name") == 0) { 149 return strcpy_s(value, len, "com.ohos.arkwebcore") == 0 ? strlen("com.ohos.arkwebcore") : -1; 150 } 151 return -1; 152} 153 154int SetParameter(const char *key, const char *value) 155{ 156 return 0; 157} 158 159int InUpdaterMode(void) 160{ 161 return 0; 162} 163 164 165#ifdef __cplusplus 166} 167#endif 168