init_service.c 2.6 KB
Newer Older
1
/*
2
 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "init_service.h"

#include <stdlib.h>
#include <string.h>
#include <sys/param.h>

#include "init.h"
#include "init_log.h"
#include "init_service_manager.h"
#include "securec.h"

X
xionglei6 已提交
26
void NotifyServiceChange(Service *service, int status)
27
{
X
xionglei6 已提交
28 29
    UNUSED(service);
    UNUSED(status);
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
}

int IsForbidden(const char *fieldStr)
{
    size_t fieldLen = strlen(fieldStr);
    size_t forbidStrLen = strlen(BIN_SH_NOT_ALLOWED);
    if (fieldLen == forbidStrLen) {
        if (strncmp(fieldStr, BIN_SH_NOT_ALLOWED, fieldLen) == 0) {
            return 1;
        }
        return 0;
    } else if (fieldLen > forbidStrLen) {
        // "/bin/shxxxx" is valid but "/bin/sh xxxx" is invalid
        if (strncmp(fieldStr, BIN_SH_NOT_ALLOWED, forbidStrLen) == 0) {
            if (fieldStr[forbidStrLen] == ' ') {
                return 1;
            }
        }
        return 0;
    } else {
        return 0;
    }
}

int SetImportantValue(Service *service, const char *attrName, int value, int flag)
{
    UNUSED(attrName);
    UNUSED(flag);
    INIT_ERROR_CHECK(service != NULL, return SERVICE_FAILURE, "Set service attr failed! null ptr.");
    if (value != 0) {
        service->attribute |= SERVICE_ATTR_IMPORTANT;
    }
    return SERVICE_SUCCESS;
}

X
xionglei6 已提交
65
int ServiceExec(const Service *service)
66 67 68
{
    INIT_ERROR_CHECK(service != NULL && service->pathArgs.count > 0,
        return SERVICE_FAILURE, "Exec service failed! null ptr.");
X
xionglei6 已提交
69
    if (execv(service->pathArgs.argv[0], service->pathArgs.argv) != 0) {
C
fix log  
cheng_jinsong 已提交
70
        INIT_LOGE("Service %s execv failed! err=%d.", service->name, errno);
71 72 73
        return errno;
    }
    return SERVICE_SUCCESS;
X
xionglei6 已提交
74
}
75 76 77 78 79 80 81 82 83 84

int SetAccessToken(const Service *service)
{
    return SERVICE_SUCCESS;
}

void GetAccessToken(void)
{
    return;
}
C
cheng_jinsong 已提交
85 86 87 88 89 90 91 92 93 94 95 96

void IsEnableSandbox(void)
{
    return;
}

void SetServiceEnterSandbox(const char *path, unsigned int attribute)
{
    UNUSED(path);
    UNUSED(attribute);
    return;
}