• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "init_cmds.h"
16 
17 #include <dlfcn.h>
18 #include <errno.h>
19 #include <fcntl.h>
20 #include <net/if.h>
21 #include <stdbool.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <sys/ioctl.h>
25 #include <sys/mount.h>
26 #include <sys/resource.h>
27 #include <sys/stat.h>
28 #include <sys/syscall.h>
29 #include <sys/sysmacros.h>
30 #include <sys/wait.h>
31 #include <unistd.h>
32 #include <linux/module.h>
33 
34 #include "bootstage.h"
35 #include "fs_manager/fs_manager.h"
36 #include "init_cmdexecutor.h"
37 #include "init_jobs_internal.h"
38 #include "init_log.h"
39 #include "init_param.h"
40 #include "init_service_manager.h"
41 #include "init_utils.h"
42 #include "sandbox.h"
43 #include "sandbox_namespace.h"
44 #include "securec.h"
45 #include "fscrypt_utils.h"
46 
47 #ifdef SUPPORT_PROFILER_HIDEBUG
48 #include <hidebug_base.h>
49 #endif
50 
51 #define FSCRYPT_POLICY_BUF_SIZE (60)
52 #define DECIMAL 10
53 #define OCTAL 8
54 
GetParamValue(const char * symValue,unsigned int symLen,char * paramValue,unsigned int paramLen)55 int GetParamValue(const char *symValue, unsigned int symLen, char *paramValue, unsigned int paramLen)
56 {
57     INIT_CHECK_RETURN_VALUE((symValue != NULL) && (paramValue != NULL) && (paramLen != 0), -1);
58     char tmpName[PARAM_NAME_LEN_MAX] = { 0 };
59     int ret;
60     uint32_t curr = 0;
61     char *start = (char *)symValue;
62     if (symLen > strlen(symValue)) {
63         return -1;
64     }
65     char *end = (char *)symValue + symLen;
66     do {
67         char *begin = strchr(start, '$');
68         if (begin == NULL || begin >= end) { // not has '$' copy the original string
69             ret = strncpy_s(paramValue + curr, paramLen - curr, start, symLen);
70             INIT_ERROR_CHECK(ret == EOK, return -1, "Failed to copy start %s", start);
71             break;
72         } else {
73             ret = memcpy_s(paramValue + curr, paramLen - curr, start, begin - start);
74             INIT_ERROR_CHECK(ret == 0, return -1, "Failed to copy first value %s", symValue);
75             curr += begin - start;
76         }
77         while (*begin != '{') {
78             INIT_CHECK_RETURN_VALUE(*begin != '\0', -1);
79             begin++;
80         }
81         begin++;
82         char *left = strchr(begin, '}');
83         INIT_CHECK_RETURN_VALUE(left != NULL, -1);
84 
85         // copy param name
86         ret = strncpy_s(tmpName, PARAM_NAME_LEN_MAX, begin, left - begin);
87         INIT_ERROR_CHECK(ret == EOK, return -1, "Invalid param name %s", symValue);
88         if (paramLen < curr) {
89             INIT_LOGE("Failed to get param value over max length");
90             return -1;
91         }
92         uint32_t valueLen = paramLen - curr;
93         ret = SystemReadParam(tmpName, paramValue + curr, &valueLen);
94         INIT_ERROR_CHECK(ret == 0, return -1, "Failed to get param %s", tmpName);
95         curr += valueLen;
96         left++;
97         if ((unsigned int)(left - symValue) >= symLen) {
98             break;
99         }
100         start = left;
101     } while (1);
102     return 0;
103 }
104 
SyncExecCommand(int argc,char * const * argv)105 static int SyncExecCommand(int argc, char * const *argv)
106 {
107     INIT_LOGI("Sync exec: %s", argv[0]);
108     pid_t pid = fork();
109     INIT_ERROR_CHECK(!(pid < 0), return -1, "Fork new process to format failed: %d", errno);
110     if (pid == 0) {
111         INIT_CHECK_ONLY_ELOG(execv(argv[0], argv) == 0, "execv %s failed! err %d.", argv[0], errno);
112         exit(-1);
113     }
114     int status;
115     pid_t ret = waitpid(pid, &status, 0);
116     if (ret != pid) {
117         INIT_LOGE("Failed to wait pid %d, errno %d", pid, errno);
118         return -1;
119     }
120     INIT_LOGI("Sync exec: %s result %d %d", argv[0], WEXITSTATUS(status), WIFEXITED(status));
121     return WEXITSTATUS(status);
122 }
123 
DoIfup(const struct CmdArgs * ctx)124 static void DoIfup(const struct CmdArgs *ctx)
125 {
126     struct ifreq interface;
127     INIT_ERROR_CHECK(strncpy_s(interface.ifr_name, IFNAMSIZ - 1, ctx->argv[0], strlen(ctx->argv[0])) == EOK,
128         return, "DoIfup failed to copy interface name");
129     INIT_LOGV("interface name: %s", interface.ifr_name);
130 
131     int fd = socket(AF_INET, SOCK_DGRAM, 0);
132     INIT_ERROR_CHECK(fd >= 0, return, "DoIfup failed to create socket, err = %d", errno);
133 
134     if (ioctl(fd, SIOCGIFFLAGS, &interface) >= 0) {
135         interface.ifr_flags |= IFF_UP;
136         INIT_CHECK_ONLY_ELOG(ioctl(fd, SIOCSIFFLAGS, &interface) >= 0,
137             "DoIfup failed to do ioctl with command \"SIOCSIFFLAGS\", err = %d", errno);
138     }
139     close(fd);
140 }
141 
142 // format insmod <ko name> [-f] [options]
DoInsmod(const struct CmdArgs * ctx)143 static void DoInsmod(const struct CmdArgs *ctx)
144 {
145     int index = 0;
146     int flags = 0;
147     char *fileName = NULL;
148     if (ctx->argc > index) {
149         fileName = ctx->argv[index];
150         index++;
151     }
152     INIT_ERROR_CHECK(fileName != NULL, return, "Can not find file name from param %s", ctx->argv[0]);
153     INIT_LOGV("Install mode %s ", fileName);
154     char *realPath = GetRealPath(fileName);
155     INIT_ERROR_CHECK(realPath != NULL, return, "Can not get real file name from param %s", ctx->argv[0]);
156     if (ctx->argc > 1 && ctx->argv[1] != NULL && strcmp(ctx->argv[1], "-f") == 0) { // [-f]
157         flags = MODULE_INIT_IGNORE_VERMAGIC | MODULE_INIT_IGNORE_MODVERSIONS;
158         index++;
159     }
160     char *options = BuildStringFromCmdArg(ctx, index); // [options]
161     int fd = open(realPath, O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
162     if (fd >= 0) {
163         int rc = syscall(__NR_finit_module, fd, options, flags);
164         if (rc == -1) {
165             INIT_LOGE("Failed to install kernel module for %s failed options %s err: %d", realPath, options, errno);
166         }
167     }
168     if (options != NULL) {
169         free(options);
170     }
171     if (fd >= 0) {
172         close(fd);
173     }
174     free(realPath);
175     return;
176 }
177 
DoSetParam(const struct CmdArgs * ctx)178 static void DoSetParam(const struct CmdArgs *ctx)
179 {
180     INIT_LOGV("set param name: %s, value %s ", ctx->argv[0], ctx->argv[1]);
181     SystemWriteParam(ctx->argv[0], ctx->argv[1]);
182 }
183 
DoLoadPersistParams(const struct CmdArgs * ctx)184 static void DoLoadPersistParams(const struct CmdArgs *ctx)
185 {
186     INIT_LOGV("LoadPersistParams");
187     LoadPersistParams();
188     HookMgrExecute(GetBootStageHookMgr(), INIT_POST_PERSIST_PARAM_LOAD, NULL, NULL);
189 }
190 
DoTriggerCmd(const struct CmdArgs * ctx)191 static void DoTriggerCmd(const struct CmdArgs *ctx)
192 {
193     INIT_LOGV("DoTrigger :%s", ctx->argv[0]);
194     DoTriggerExec(ctx->argv[0]);
195 }
196 
DoLoadDefaultParams(const struct CmdArgs * ctx)197 static void DoLoadDefaultParams(const struct CmdArgs *ctx)
198 {
199     int mode = 0;
200     if (ctx->argc > 1 && strcmp(ctx->argv[1], "onlyadd") == 0) {
201         mode = LOAD_PARAM_ONLY_ADD;
202     }
203     INIT_LOGV("DoLoadDefaultParams args : %s %d", ctx->argv[0], mode);
204     LoadDefaultParams(ctx->argv[0], mode);
205 }
206 
DoSyncExec(const struct CmdArgs * ctx)207 static void DoSyncExec(const struct CmdArgs *ctx)
208 {
209     // format: syncexec /xxx/xxx/xxx xxx
210     INIT_ERROR_CHECK(ctx != NULL && ctx->argv[0] != NULL, return, "DoSyncExec: invalid arguments");
211     SyncExecCommand(ctx->argc, ctx->argv);
212     return;
213 }
214 
DoExec(const struct CmdArgs * ctx)215 static void DoExec(const struct CmdArgs *ctx)
216 {
217     // format: exec /xxx/xxx/xxx xxx
218     INIT_ERROR_CHECK(ctx != NULL && ctx->argv[0] != NULL, return, "DoExec: invalid arguments");
219     pid_t pid = fork();
220     INIT_ERROR_CHECK(pid >= 0, return, "DoExec: failed to fork child process to exec \"%s\"", ctx->argv[0]);
221 
222     if (pid == 0) {
223         OpenHidebug(ctx->argv[0]);
224         int ret = execv(ctx->argv[0], ctx->argv);
225         INIT_CHECK_ONLY_ELOG(ret != -1, "DoExec: execute \"%s\" failed: %d.", ctx->argv[0], errno);
226         _exit(0x7f);
227     }
228     return;
229 }
230 
DoSymlink(const struct CmdArgs * ctx)231 static void DoSymlink(const struct CmdArgs *ctx)
232 {
233     // format: symlink /xxx/xxx/xxx /xxx/xxx/xxx
234     int ret = symlink(ctx->argv[0], ctx->argv[1]);
235     if (ret != 0 && errno != EEXIST) {
236         INIT_LOGE("DoSymlink: link %s to %s failed: %d", ctx->argv[0], ctx->argv[1], errno);
237     }
238 }
239 
GetDeviceMode(const char * deviceStr)240 static mode_t GetDeviceMode(const char *deviceStr)
241 {
242     switch (*deviceStr) {
243         case 'b':
244         case 'B':
245             return S_IFBLK;
246         case 'c':
247         case 'C':
248             return S_IFCHR;
249         case 'f':
250         case 'F':
251             return S_IFIFO;
252         default:
253             return -1;
254     }
255 }
256 
DoMakeNode(const struct CmdArgs * ctx)257 static void DoMakeNode(const struct CmdArgs *ctx)
258 {
259     // format: mknod path b 0644 1 9
260     const int deviceTypePos = 1;
261     const int authorityPos = 2;
262     const int majorDevicePos = 3;
263     const int minorDevicePos = 4;
264     INIT_ERROR_CHECK(access(ctx->argv[1], F_OK), return, "DoMakeNode failed, path has sexisted");
265     mode_t deviceMode = GetDeviceMode(ctx->argv[deviceTypePos]);
266     errno = 0;
267     unsigned int major = strtoul(ctx->argv[majorDevicePos], NULL, DECIMAL);
268     INIT_CHECK_ONLY_ELOG(errno != ERANGE, "Failed to strtoul %s", ctx->argv[majorDevicePos]);
269     unsigned int minor = strtoul(ctx->argv[minorDevicePos], NULL, DECIMAL);
270     INIT_CHECK_ONLY_ELOG(errno != ERANGE, "Failed to strtoul %s", ctx->argv[minorDevicePos]);
271     mode_t authority = strtoul(ctx->argv[authorityPos], NULL, OCTAL);
272     INIT_CHECK_ONLY_ELOG(errno != ERANGE, "Failed to strtoul %s", ctx->argv[authorityPos]);
273     int ret = mknod(ctx->argv[0], deviceMode | authority, makedev(major, minor));
274     if (ret != 0) {
275         INIT_LOGE("DoMakeNode: path: %s failed: %d", ctx->argv[0], errno);
276     }
277 }
278 
DoMakeDevice(const struct CmdArgs * ctx)279 static void DoMakeDevice(const struct CmdArgs *ctx)
280 {
281     // format: makedev major minor
282     errno = 0;
283     unsigned int major = strtoul(ctx->argv[0], NULL, DECIMAL);
284     INIT_CHECK_ONLY_ELOG(errno != ERANGE, "Failed to strtoul %s", ctx->argv[0]);
285     unsigned int minor = strtoul(ctx->argv[1], NULL, DECIMAL);
286     INIT_CHECK_ONLY_ELOG(errno != ERANGE, "Failed to strtoul %s", ctx->argv[1]);
287     dev_t deviceId = makedev(major, minor);
288     INIT_CHECK_ONLY_ELOG(deviceId >= 0, "DoMakedevice \" major:%s, minor:%s \" failed :%d ", ctx->argv[0],
289         ctx->argv[1], errno);
290     return;
291 }
292 
DoMountFstabFile(const struct CmdArgs * ctx)293 static void DoMountFstabFile(const struct CmdArgs *ctx)
294 {
295     INIT_LOGI("Mount partitions from fstab file \" %s \"", ctx->argv[0]);
296     int ret = MountAllWithFstabFile(ctx->argv[0], 0);
297     INIT_LOGI("Mount partitions from fstab file \" %s \" finish ret %d", ctx->argv[0], ret);
298     HookMgrExecute(GetBootStageHookMgr(), INIT_MOUNT_STAGE, NULL, NULL);
299 }
300 
DoUmountFstabFile(const struct CmdArgs * ctx)301 static void DoUmountFstabFile(const struct CmdArgs *ctx)
302 {
303     INIT_LOGI("Umount partitions from fstab file \" %s \"", ctx->argv[0]);
304     int rc = UmountAllWithFstabFile(ctx->argv[0]);
305     if (rc < 0) {
306         INIT_LOGE("Run command umount_fstab failed");
307     } else {
308         INIT_LOGI("Umount partitions from fstab done");
309     }
310 }
311 
DoRestorecon(const struct CmdArgs * ctx)312 static void DoRestorecon(const struct CmdArgs *ctx)
313 {
314     int ret;
315     INIT_CMD_INFO cmdInfo;
316     cmdInfo.cmdName = "restorecon";
317     cmdInfo.cmdContent = ctx->argv[0];
318     cmdInfo.reserved = NULL;
319     if ((ctx->argc > 1) && strcmp(ctx->argv[0], "-F") == 0) {
320         cmdInfo.cmdContent = ctx->argv[1];
321     }
322 
323     HOOK_EXEC_OPTIONS options;
324     options.flags = TRAVERSE_STOP_WHEN_ERROR;
325     options.preHook = NULL;
326     options.postHook = NULL;
327     ret = HookMgrExecute(GetBootStageHookMgr(), INIT_RESTORECON, (void*)(&cmdInfo), (void*)(&options));
328     if (ret == 0) {
329         return;
330     }
331     if ((ctx->argc > 1) && strcmp(ctx->argv[0], "-F") == 0) {
332         PluginExecCmdByName("restoreContentRecurseForce", ctx->argv[1]);
333     } else {
334         PluginExecCmdByName("restoreContentRecurse", ctx->argv[0]);
335     }
336     return;
337 }
338 
DoLoadAccessTokenId(const struct CmdArgs * ctx)339 static void DoLoadAccessTokenId(const struct CmdArgs *ctx)
340 {
341     LoadAccessTokenId();
342 }
343 
FilterService(const Service * service,const char ** exclude,int size)344 static int FilterService(const Service *service, const char **exclude, int size)
345 {
346     for (int i = 0; i < size; i++) {
347         if (exclude[i] != NULL && strcmp(service->name, exclude[i]) == 0) {
348             return 1;
349         }
350     }
351     return 0;
352 }
353 
DoStopAllServices(const struct CmdArgs * ctx)354 static void DoStopAllServices(const struct CmdArgs *ctx)
355 {
356     int flags = SERVICE_ATTR_INVALID;
357     if (ctx->argc >= 1 && strcmp(ctx->argv[0], "true") == 0) {
358         flags |= SERVICE_ATTR_NEEDWAIT;
359         StopAllServices(flags, (const char **)(&ctx->argv[1]), ctx->argc - 1, FilterService);
360     } else {
361         StopAllServices(flags, (const char **)ctx->argv, ctx->argc, FilterService);
362     }
363     return;
364 }
365 
DoUmount(const struct CmdArgs * ctx)366 static void DoUmount(const struct CmdArgs *ctx)
367 {
368     INIT_LOGI("DoUmount %s",  ctx->argv[0]);
369     MountStatus status = GetMountStatusForMountPoint(ctx->argv[0]);
370     if (status == MOUNT_MOUNTED) {
371         int ret = umount(ctx->argv[0]);
372         if ((ret != 0) && (ctx->argc > 1) && (strcmp(ctx->argv[1], "MNT_FORCE") == 0)) {
373             ret = umount2(ctx->argv[0], MNT_FORCE);
374         }
375         INIT_CHECK_ONLY_ELOG(ret == 0, "Failed to umount %s, errno %d", ctx->argv[0], errno);
376     } else if (status == MOUNT_UMOUNTED) {
377         INIT_LOGI("%s is already umounted", ctx->argv[0]);
378     } else {
379         INIT_LOGE("Failed to get %s mount status", ctx->argv[0]);
380     }
381 }
382 
DoSync(const struct CmdArgs * ctx)383 static void DoSync(const struct CmdArgs *ctx)
384 {
385     sync();
386 }
387 
DoTimerStart(const struct CmdArgs * ctx)388 static void DoTimerStart(const struct CmdArgs *ctx)
389 {
390     INIT_LOGI("Timer start service with arg = %s", ctx->argv[0]);
391     char *arg = ctx->argv[0];
392     int count = 0;
393     int expectedCount = 2;
394     char **splitArgs = SplitStringExt(ctx->argv[0], "|", &count, expectedCount);
395     if (splitArgs == NULL) {
396         INIT_LOGE("Call timer_start with invalid arguments");
397         return;
398     }
399 
400     if (count != expectedCount) {
401         INIT_LOGE("Call timer_start with unexpected arguments %s", arg);
402         FreeStringVector(splitArgs, count);
403         return;
404     }
405 
406     Service *service = GetServiceByName(splitArgs[0]);
407     if (service == NULL) {
408         INIT_LOGE("Cannot find service in timer_start command");
409         FreeStringVector(splitArgs, count);
410         return;
411     }
412 
413     errno = 0;
414     uint64_t timeout = strtoull(splitArgs[1], NULL, DECIMAL_BASE);
415     if (errno != 0) {
416         INIT_LOGE("call timer_start with invalid timer");
417         FreeStringVector(splitArgs, count);
418         return;
419     }
420     // not need this anymore , release memory.
421     FreeStringVector(splitArgs, count);
422     ServiceStartTimer(service, timeout);
423 }
424 
DoTimerStop(const struct CmdArgs * ctx)425 static void DoTimerStop(const struct CmdArgs *ctx)
426 {
427     INIT_LOGI("Stop service timer with arg = %s", ctx->argv[0]);
428     const char *serviceName = ctx->argv[0];
429     Service *service = GetServiceByName(serviceName);
430     if (service == NULL) {
431         INIT_LOGE("Cannot find service in timer_stop command");
432         return;
433     }
434     ServiceStopTimer(service);
435 }
436 
InitFscryptPolicy(void)437 static bool InitFscryptPolicy(void)
438 {
439     char policy[FSCRYPT_POLICY_BUF_SIZE];
440     if (LoadFscryptPolicy(policy, FSCRYPT_POLICY_BUF_SIZE) == 0) {
441         if (SetFscryptSysparam(policy) == 0) {
442             return true;
443         }
444     }
445     return false;
446 }
447 
DoInitGlobalKey(const struct CmdArgs * ctx)448 static void DoInitGlobalKey(const struct CmdArgs *ctx)
449 {
450     INIT_LOGV("Do init global key start");
451     const char *dataDir = "/data";
452     if (strncmp(ctx->argv[0], dataDir, strlen(dataDir)) != 0) {
453         INIT_LOGE("Not data partitation");
454         return;
455     }
456     if (!InitFscryptPolicy()) {
457         INIT_LOGW("Init fscrypt failed, not enable fscrypt");
458         return;
459     }
460 
461     char * const argv[] = {
462         "/system/bin/sdc",
463         "filecrypt",
464         "init_global_key",
465         NULL
466     };
467     int argc = ARRAY_LENGTH(argv);
468     int ret = SyncExecCommand(argc, argv);
469     INIT_CMD_INFO cmdInfo;
470     cmdInfo.cmdName = "init_global_key";
471     cmdInfo.cmdContent = (const char *)&ret;
472     cmdInfo.reserved = NULL;
473     HookMgrExecute(GetBootStageHookMgr(), INIT_POST_DATA_UNENCRYPT, (void*)(&cmdInfo), NULL);
474 }
475 
DoInitMainUser(const struct CmdArgs * ctx)476 static void DoInitMainUser(const struct CmdArgs *ctx)
477 {
478     char * const argv[] = {
479         "/system/bin/sdc",
480         "filecrypt",
481         "init_main_user",
482         NULL
483     };
484     int argc = ARRAY_LENGTH(argv);
485     int ret = SyncExecCommand(argc, argv);
486     INIT_CMD_INFO cmdInfo;
487     cmdInfo.cmdName = "init_main_user";
488     cmdInfo.cmdContent = (const char *)&ret;
489     cmdInfo.reserved = NULL;
490     HookMgrExecute(GetBootStageHookMgr(), INIT_POST_DATA_UNENCRYPT, (void*)(&cmdInfo), NULL);
491 }
492 
DoMkswap(const struct CmdArgs * ctx)493 static void DoMkswap(const struct CmdArgs *ctx)
494 {
495     char *const argv[] = {
496         "/system/bin/mkswap",
497         ctx->argv[0],
498         NULL
499     };
500     int argc = ARRAY_LENGTH(argv);
501     SyncExecCommand(argc, argv);
502 }
503 
DoSwapon(const struct CmdArgs * ctx)504 static void DoSwapon(const struct CmdArgs *ctx)
505 {
506     char *const argv[] = {
507         "/system/bin/swapon",
508         ctx->argv[0],
509         NULL
510     };
511     int argc = ARRAY_LENGTH(argv);
512     SyncExecCommand(argc, argv);
513 }
514 
DoMkSandbox(const struct CmdArgs * ctx)515 static void DoMkSandbox(const struct CmdArgs *ctx)
516 {
517     INIT_LOGV("Do make sandbox start");
518     const char *sandbox = ctx->argv[0];
519     InitDefaultNamespace();
520     if (!InitSandboxWithName(sandbox)) {
521         INIT_LOGE("Failed to init sandbox with name %s.", sandbox);
522     }
523 
524     if (PrepareSandbox(sandbox) != 0) {
525         INIT_LOGE("Failed to prepare sandbox %s.", sandbox);
526         DestroySandbox(sandbox);
527     }
528     if (EnterDefaultNamespace() < 0) {
529         INIT_LOGE("Failed to set default namespace.");
530     }
531     CloseDefaultNamespace();
532 }
533 
534 static const struct CmdTable g_cmdTable[] = {
535     { "syncexec ", 1, 10, 0, DoSyncExec },
536     { "exec ", 1, 10, 0, DoExec },
537     { "mknode ", 5, 5, 0, DoMakeNode },
538     { "makedev ", 2, 2, 0, DoMakeDevice },
539     { "symlink ", 2, 2, 1, DoSymlink },
540     { "trigger ", 0, 1, 0, DoTriggerCmd },
541     { "insmod ", 1, 10, 1, DoInsmod },
542     { "setparam ", 2, 2, 0, DoSetParam },
543     { "load_persist_params ", 0, 1, 0, DoLoadPersistParams },
544     { "load_param ", 1, 2, 0, DoLoadDefaultParams },
545     { "load_access_token_id ", 0, 1, 0, DoLoadAccessTokenId },
546     { "ifup ", 1, 1, 1, DoIfup },
547     { "mount_fstab ", 1, 1, 0, DoMountFstabFile },
548     { "umount_fstab ", 1, 1, 0, DoUmountFstabFile },
549     { "restorecon ", 1, 2, 1, DoRestorecon },
550     { "stopAllServices ", 0, 10, 0, DoStopAllServices },
551     { "umount ", 1, 1, 0, DoUmount },
552     { "sync ", 0, 1, 0, DoSync },
553     { "timer_start", 1, 1, 0, DoTimerStart },
554     { "timer_stop", 1, 1, 0, DoTimerStop },
555     { "init_global_key ", 1, 1, 0, DoInitGlobalKey },
556     { "init_main_user ", 0, 1, 0, DoInitMainUser },
557     { "mkswap", 1, 1, 0, DoMkswap},
558     { "swapon", 1, 1, 0, DoSwapon},
559     { "mksandbox", 1, 1, 0, DoMkSandbox},
560 };
561 
GetCmdTable(int * number)562 const struct CmdTable *GetCmdTable(int *number)
563 {
564     *number = (int)ARRAY_LENGTH(g_cmdTable);
565     return g_cmdTable;
566 }
567 
OpenHidebug(const char * name)568 void OpenHidebug(const char *name)
569 {
570 #ifdef SUPPORT_PROFILER_HIDEBUG
571     InitEnvironmentParam(name);
572 #endif
573 }
574 
SetFileCryptPolicy(const char * dir)575 int SetFileCryptPolicy(const char *dir)
576 {
577     if (dir == NULL) {
578         INIT_LOGE("SetFileCryptPolicy:dir is null");
579         return -EINVAL;
580     }
581     return FscryptPolicyEnable(dir);
582 }
583