• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-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_service.h"
16 
17 #include <stdlib.h>
18 #include <string.h>
19 #include <sys/param.h>
20 
21 #include "init.h"
22 #include "init_log.h"
23 #include "init_service_manager.h"
24 #include "securec.h"
25 
NotifyServiceChange(Service * service,int status)26 void NotifyServiceChange(Service *service, int status)
27 {
28     UNUSED(service);
29     UNUSED(status);
30 }
31 
IsForbidden(const char * fieldStr)32 int IsForbidden(const char *fieldStr)
33 {
34     size_t fieldLen = strlen(fieldStr);
35     size_t forbidStrLen = strlen(BIN_SH_NOT_ALLOWED);
36     if (fieldLen == forbidStrLen) {
37         if (strncmp(fieldStr, BIN_SH_NOT_ALLOWED, fieldLen) == 0) {
38             return 1;
39         }
40         return 0;
41     } else if (fieldLen > forbidStrLen) {
42         // "/bin/shxxxx" is valid but "/bin/sh xxxx" is invalid
43         if (strncmp(fieldStr, BIN_SH_NOT_ALLOWED, forbidStrLen) == 0) {
44             if (fieldStr[forbidStrLen] == ' ') {
45                 return 1;
46             }
47         }
48         return 0;
49     } else {
50         return 0;
51     }
52 }
53 
SetImportantValue(Service * service,const char * attrName,int value,int flag)54 int SetImportantValue(Service *service, const char *attrName, int value, int flag)
55 {
56     UNUSED(attrName);
57     UNUSED(flag);
58     INIT_ERROR_CHECK(service != NULL, return SERVICE_FAILURE, "Set service attr failed! null ptr.");
59     if (value != 0) {
60         service->attribute |= SERVICE_ATTR_IMPORTANT;
61     }
62     return SERVICE_SUCCESS;
63 }
64 
ServiceExec(const Service * service)65 int ServiceExec(const Service *service)
66 {
67     INIT_ERROR_CHECK(service != NULL && service->pathArgs.count > 0,
68         return SERVICE_FAILURE, "Exec service failed! null ptr.");
69     if (execv(service->pathArgs.argv[0], service->pathArgs.argv) != 0) {
70         INIT_LOGE("Service %s execv failed! err=%d.", service->name, errno);
71         return errno;
72     }
73     return SERVICE_SUCCESS;
74 }
75 
SetAccessToken(const Service * service)76 int SetAccessToken(const Service *service)
77 {
78     return SERVICE_SUCCESS;
79 }
80 
GetAccessToken(void)81 void GetAccessToken(void)
82 {
83     return;
84 }
85 
IsEnableSandbox(void)86 void IsEnableSandbox(void)
87 {
88     return;
89 }
90 
SetServiceEnterSandbox(const char * path,unsigned int attribute)91 void SetServiceEnterSandbox(const char *path, unsigned int attribute)
92 {
93     UNUSED(path);
94     UNUSED(attribute);
95     return;
96 }
97