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
52 namespace OHOS {
53 namespace system {
GetIntParameter(const std::string & key,bool def,bool arg1=false,bool arg2=false)54 bool GetIntParameter(const std::string &key, bool def, bool arg1 = false, bool arg2 = false)
55 {
56 return def;
57 }
58
GetBoolParameter(const std::string & key,bool def)59 bool GetBoolParameter(const std::string &key, bool def)
60 {
61 return def;
62 }
63 } // namespace system
64
65 namespace Security {
66 namespace AccessToken {
GetRenderTokenID(uint64_t tokenId)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
HapContext()76 HapContext::HapContext() {}
~HapContext()77 HapContext::~HapContext() {}
HapDomainSetcontext(HapDomainInfo & hapDomainInfo)78 int HapContext::HapDomainSetcontext(HapDomainInfo &hapDomainInfo)
79 {
80 return 0;
81 }
82 #endif
83
84 #ifdef __cplusplus
85 extern "C" {
86 #endif
ResetParamSecurityLabel()87 void ResetParamSecurityLabel() {}
88
SetSelfTokenID(uint64_t tokenId)89 int SetSelfTokenID(uint64_t tokenId)
90 {
91 return 0;
92 }
93
SetTraceDisabled(int disable)94 void SetTraceDisabled(int disable) {}
95
96 #ifdef WITH_SECCOMP
SetSeccompPolicyWithName(SeccompFilterType filter,const char * filterName)97 bool 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
IsEnableSeccomp(void)104 bool IsEnableSeccomp(void)
105 {
106 return true;
107 }
108 #endif
109
GetControlSocket(const char * name)110 int GetControlSocket(const char *name)
111 {
112 return -1;
113 }
114
115 static bool g_developerMode = true;
SetDeveloperMode(bool mode)116 void SetDeveloperMode(bool mode)
117 {
118 g_developerMode = mode;
119 }
120
GetParameter(const char * key,const char * def,char * value,uint32_t len)121 int 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 return -1;
149 }
150
SetParameter(const char * key,const char * value)151 int SetParameter(const char *key, const char *value)
152 {
153 return 0;
154 }
155
InUpdaterMode(void)156 int InUpdaterMode(void)
157 {
158 return 0;
159 }
160
161
162 #ifdef __cplusplus
163 }
164 #endif
165