mirror of
https://gitee.com/openharmony/startup_appspawn
synced 2024-11-27 01:00:38 +00:00
delete innerkit_new
Signed-off-by: zhongning5 <zhongning5@huawei.com>
This commit is contained in:
parent
6cf17abd2b
commit
121f8b2316
@ -14,7 +14,7 @@
|
||||
ability_runtime_path = "//foundation/ability/ability_runtime"
|
||||
ability_runtime_kits_path = "${ability_runtime_path}/frameworks/kits"
|
||||
appspawn_path = "//base/startup/appspawn"
|
||||
appspawn_innerkits_path = "//base/startup/appspawn/interfaces/innerkits_new"
|
||||
appspawn_innerkits_path = "//base/startup/appspawn/interfaces/innerkits"
|
||||
startup_path = "//base/startup"
|
||||
subsystem_name = "startup"
|
||||
part_name = "appspawn"
|
||||
|
14
bundle.json
14
bundle.json
@ -80,22 +80,12 @@
|
||||
"inner_kits": [
|
||||
{
|
||||
"header": {
|
||||
"header_base": "//base/startup/appspawn/interfaces/innerkits_new/include/",
|
||||
"header_base": "//base/startup/appspawn/interfaces/innerkits/include/",
|
||||
"header_files": [
|
||||
"appspawn.h"
|
||||
]
|
||||
},
|
||||
"name": "//base/startup/appspawn/interfaces/innerkits_new/client:appspawn_client"
|
||||
},
|
||||
{
|
||||
"header": {
|
||||
"header_base": "//base/startup/appspawn/interfaces/innerkits/include/",
|
||||
"header_files": [
|
||||
"appspawn_socket.h",
|
||||
"client_socket.h"
|
||||
]
|
||||
},
|
||||
"name": "//base/startup/appspawn/interfaces/innerkits:appspawn_socket_client"
|
||||
"name": "//base/startup/appspawn/interfaces/innerkits/client:appspawn_client"
|
||||
},
|
||||
{
|
||||
"header": {
|
||||
|
@ -1,52 +0,0 @@
|
||||
# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
# 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.
|
||||
|
||||
import("//base/startup/appspawn/appspawn.gni")
|
||||
import("//build/ohos.gni")
|
||||
|
||||
config("exported_header_files") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [ "include/" ]
|
||||
}
|
||||
|
||||
ohos_static_library("appspawn_socket_client") {
|
||||
if (!defined(ohos_lite)) {
|
||||
sources = [
|
||||
"client/appspawn_socket.cpp",
|
||||
"client/client_socket.cpp",
|
||||
"src/appspawn_mount_permission.cpp",
|
||||
]
|
||||
include_dirs = [
|
||||
"//base/startup/appspawn",
|
||||
"//base/startup/appspawn/util/include",
|
||||
"include",
|
||||
"//base/startup/appspawn/common",
|
||||
]
|
||||
defines = []
|
||||
if (is_asan) {
|
||||
defines += [ "APPSPAWN_ASAN" ]
|
||||
}
|
||||
public_configs = [ ":exported_header_files" ]
|
||||
deps = []
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"config_policy:configpolicy_util",
|
||||
"hilog:libhilog",
|
||||
"init:libbegetutil",
|
||||
"json:nlohmann_json_static",
|
||||
]
|
||||
}
|
||||
|
||||
subsystem_name = "${subsystem_name}"
|
||||
part_name = "${part_name}"
|
||||
}
|
@ -1,141 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* 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 "appspawn_socket.h"
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <linux/tcp.h>
|
||||
#include <linux/in.h>
|
||||
#include <cerrno>
|
||||
|
||||
#include "appspawn_server.h"
|
||||
#include "pubdef.h"
|
||||
#include "securec.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppSpawn {
|
||||
AppSpawnSocket::AppSpawnSocket(const std::string &name)
|
||||
{
|
||||
socketName_ = name;
|
||||
}
|
||||
|
||||
AppSpawnSocket::~AppSpawnSocket()
|
||||
{
|
||||
if (socketFd_ > 0) {
|
||||
CloseSocket(socketFd_);
|
||||
socketFd_ = -1;
|
||||
}
|
||||
}
|
||||
|
||||
int AppSpawnSocket::GetSocketFd() const
|
||||
{
|
||||
return socketFd_;
|
||||
}
|
||||
|
||||
int AppSpawnSocket::PackSocketAddr()
|
||||
{
|
||||
APPSPAWN_CHECK(!socketName_.empty(), return -EINVAL, "Invalid socket name: empty");
|
||||
(void)memset_s(&socketAddr_, sizeof(socketAddr_), 0, sizeof(socketAddr_));
|
||||
|
||||
socklen_t pathLen = 0;
|
||||
if (socketName_[0] == '/') {
|
||||
pathLen = socketName_.length();
|
||||
} else {
|
||||
pathLen = socketDir_.length() + socketName_.length();
|
||||
}
|
||||
socklen_t pathSize = sizeof(socketAddr_.sun_path);
|
||||
if (pathLen >= pathSize) {
|
||||
APPSPAWN_LOGE("Invalid socket name: '%{public}s' too long", socketName_.c_str());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int len = 0;
|
||||
if (socketName_[0] == '/') {
|
||||
len = snprintf_s(socketAddr_.sun_path, pathSize, (pathSize - 1), "%s", socketName_.c_str());
|
||||
} else {
|
||||
len = snprintf_s(socketAddr_.sun_path, pathSize, (pathSize - 1), "%s%s",
|
||||
socketDir_.c_str(), socketName_.c_str());
|
||||
}
|
||||
APPSPAWN_CHECK(static_cast<int>(pathLen) == len, return -1, "Failed to copy socket path");
|
||||
|
||||
socketAddr_.sun_family = AF_LOCAL;
|
||||
socketAddrLen_ = offsetof(struct sockaddr_un, sun_path) + pathLen + 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AppSpawnSocket::CreateSocket()
|
||||
{
|
||||
int socketFd = socket(AF_UNIX, SOCK_STREAM, 0); // SOCK_SEQPACKET
|
||||
APPSPAWN_CHECK(socketFd >= 0, return -errno, "Failed to create socket: %{public}d", errno);
|
||||
|
||||
int flag = 1;
|
||||
int ret = setsockopt(socketFd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int));
|
||||
APPSPAWN_LOGV("Created socket with fd %{public}d, setsockopt %{public}d", socketFd, ret);
|
||||
return socketFd;
|
||||
}
|
||||
|
||||
void AppSpawnSocket::CloseSocket(int &socketFd)
|
||||
{
|
||||
if (socketFd >= 0) {
|
||||
APPSPAWN_LOGV("Closed socket with fd %{public}d", socketFd);
|
||||
int flag = 0;
|
||||
setsockopt(socketFd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int));
|
||||
close(socketFd);
|
||||
socketFd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
int AppSpawnSocket::ReadSocketMessage(int socketFd, void *buf, int len)
|
||||
{
|
||||
if (socketFd < 0 || len <= 0 || buf == nullptr) {
|
||||
APPSPAWN_LOGE("Invalid args: socket %{public}d, len %{public}d, buf might be nullptr", socketFd, len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
APPSPAWN_CHECK(memset_s(buf, len, 0, len) == EOK, return -1, "Failed to memset read buf");
|
||||
|
||||
ssize_t rLen = TEMP_FAILURE_RETRY(read(socketFd, buf, len));
|
||||
while ((rLen < 0) && (errno == EAGAIN)) {
|
||||
rLen = TEMP_FAILURE_RETRY(read(socketFd, buf, len));
|
||||
}
|
||||
APPSPAWN_CHECK(rLen >= 0, return -EFAULT,
|
||||
"Read message from fd %{public}d error %{public}zd: %{public}d", socketFd, rLen, errno);
|
||||
|
||||
return rLen;
|
||||
}
|
||||
|
||||
int AppSpawnSocket::WriteSocketMessage(int socketFd, const void *buf, int len)
|
||||
{
|
||||
if (socketFd < 0 || len <= 0 || buf == nullptr) {
|
||||
APPSPAWN_LOGE("Invalid args: socket %{public}d, len %{public}d, buf might be nullptr", socketFd, len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t written = 0;
|
||||
ssize_t remain = static_cast<ssize_t>(len);
|
||||
const uint8_t *offset = reinterpret_cast<const uint8_t *>(buf);
|
||||
for (ssize_t wLen = 0; remain > 0; offset += wLen, remain -= wLen, written += wLen) {
|
||||
wLen = write(socketFd, offset, remain);
|
||||
APPSPAWN_LOGV("socket fd %{public}d, wLen %{public}zd", socketFd, wLen);
|
||||
bool isRet = (wLen <= 0) && (errno != EINTR);
|
||||
APPSPAWN_CHECK(!isRet, return -errno,
|
||||
"Failed to write message to fd %{public}d, error %{public}zd: %{public}d", socketFd, wLen, errno);
|
||||
}
|
||||
|
||||
return written;
|
||||
}
|
||||
} // namespace AppSpawn
|
||||
} // namespace OHOS
|
@ -1,106 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* 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 "client_socket.h"
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <cerrno>
|
||||
|
||||
#include "appspawn_server.h"
|
||||
#include "parameters.h"
|
||||
|
||||
namespace OHOS {
|
||||
#ifdef APPSPAWN_ASAN
|
||||
static constexpr int TIMEOUT_DEF = 5;
|
||||
#else
|
||||
static constexpr int TIMEOUT_DEF = 2;
|
||||
#endif
|
||||
namespace AppSpawn {
|
||||
ClientSocket::ClientSocket(const std::string &client) : AppSpawnSocket(client)
|
||||
{}
|
||||
|
||||
int ClientSocket::CreateClient()
|
||||
{
|
||||
if (socketFd_ < 0) {
|
||||
socketFd_ = CreateSocket();
|
||||
APPSPAWN_CHECK(socketFd_ >= 0, return socketFd_, "Client: Create socket failed");
|
||||
}
|
||||
|
||||
int opt = 1;
|
||||
int ret = setsockopt(socketFd_, SOL_SOCKET, SO_PASSCRED, &opt, sizeof(opt));
|
||||
APPSPAWN_CHECK(ret == 0, CloseClient(); return ret,
|
||||
"Client: set socket opt socket fd: %{public}d error: %{public}d", socketFd_, errno);
|
||||
APPSPAWN_LOGV("Client: CreateClient socket fd %{public}d ret %{public}d", socketFd_, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ClientSocket::CloseClient()
|
||||
{
|
||||
if (socketFd_ < 0) {
|
||||
APPSPAWN_LOGE("Client: Invalid connectFd %{public}d", socketFd_);
|
||||
return;
|
||||
}
|
||||
|
||||
CloseSocket(socketFd_);
|
||||
socketFd_ = -1;
|
||||
}
|
||||
|
||||
int ClientSocket::ConnectSocket(int connectFd)
|
||||
{
|
||||
if (connectFd < 0) {
|
||||
APPSPAWN_LOGE("Client: Invalid socket fd: %{public}d", connectFd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
APPSPAWN_CHECK(PackSocketAddr() == 0, return -1, "pack socket failed");
|
||||
|
||||
struct timeval timeout = {TIMEOUT_DEF, 0};
|
||||
int value = OHOS::system::GetIntParameter("persist.appspawn.client.timeout", TIMEOUT_DEF);
|
||||
if (value != TIMEOUT_DEF && value != 0) {
|
||||
timeout.tv_sec = value;
|
||||
}
|
||||
APPSPAWN_LOGI("Client: Connected on socket fd %{public}d value %{public}d", connectFd, value);
|
||||
bool isRet = (setsockopt(connectFd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) != 0) ||
|
||||
(setsockopt(connectFd, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout)) != 0);
|
||||
APPSPAWN_CHECK(!isRet, return (-1),
|
||||
"Client: Failed to set opt of socket %{public}d, err %{public}d", connectFd, errno);
|
||||
|
||||
if (connect(connectFd, reinterpret_cast<struct sockaddr *>(&socketAddr_), socketAddrLen_) < 0) {
|
||||
APPSPAWN_LOGW("Client: Connect on socket fd %{public}d, failed: %{public}d", connectFd, errno);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ClientSocket::ConnectSocket()
|
||||
{
|
||||
int ret = ConnectSocket(socketFd_);
|
||||
if (ret != 0) {
|
||||
CloseClient();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ClientSocket::WriteSocketMessage(const void *buf, int len)
|
||||
{
|
||||
return WriteSocketMessage(socketFd_, buf, len);
|
||||
}
|
||||
|
||||
int ClientSocket::ReadSocketMessage(void *buf, int len)
|
||||
{
|
||||
return ReadSocketMessage(socketFd_, buf, len);
|
||||
}
|
||||
} // namespace AppSpawn
|
||||
} // namespace OHOS
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef APPSPAWN_MOUNT_PERMISSION_H
|
||||
#define APPSPAWN_MOUNT_PERMISSION_H
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <mutex>
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppSpawn {
|
||||
class AppspawnMountPermission {
|
||||
public:
|
||||
static void GetPermissionFromJson(
|
||||
std::set<std::string> &appSandboxPremissionSet, nlohmann::json &appSandboxPremission);
|
||||
static void LoadPermissionNames(void);
|
||||
static std::set<std::string> GetMountPermissionList();
|
||||
static uint32_t GenPermissionCode(const std::set<std::string> &permissions);
|
||||
static bool IsMountPermission(uint32_t code, const std::string permission);
|
||||
private:
|
||||
static bool isLoad_;
|
||||
static std::set<std::string> appSandboxPremission_;
|
||||
static std::mutex mutex_;
|
||||
};
|
||||
} // AppSpawn
|
||||
} // OHOS
|
||||
|
||||
#endif
|
||||
|
@ -1,124 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef APPSPAWN_MSG_H
|
||||
#define APPSPAWN_MSG_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(__MUSL__)
|
||||
#ifndef APPSPAWN_TEST
|
||||
#define SOCKET_DIR "/dev/unix/socket/"
|
||||
#else
|
||||
#define SOCKET_DIR "/data/appspawn_ut/dev/unix/socket/"
|
||||
#endif
|
||||
#else
|
||||
#define SOCKET_DIR "/dev/socket/"
|
||||
#endif
|
||||
|
||||
|
||||
#define NWEBSPAWN_SOCKET_NAME "NWebSpawn"
|
||||
#define NWEBSPAWN_SERVER_NAME "nwebspawn"
|
||||
#define APPSPAWN_SOCKET_NAME "AppSpawn"
|
||||
#define APPSPAWN_SERVER_NAME "appspawn"
|
||||
#define CJAPPSPAWN_SOCKET_NAME "CJAppSpawn"
|
||||
#define CJAPPSPAWN_SERVER_NAME "cjappspawn"
|
||||
|
||||
|
||||
enum AppType {
|
||||
APP_TYPE_DEFAULT = 0, // JavaScript app
|
||||
APP_TYPE_NATIVE // Native C++ app
|
||||
};
|
||||
|
||||
typedef enum AppOperateType_ {
|
||||
DEFAULT = 0,
|
||||
GET_RENDER_TERMINATION_STATUS,
|
||||
SPAWN_NATIVE_PROCESS
|
||||
} AppOperateType;
|
||||
|
||||
#define APP_MSG_MAX_SIZE 4096 // appspawn message max size
|
||||
#define APP_LEN_PROC_NAME 256 // process name length
|
||||
#define APP_LEN_BUNDLE_NAME 256 // bundle name length
|
||||
#define APP_LEN_SO_PATH 256 // load so lib
|
||||
#define APP_MAX_GIDS 64
|
||||
#define APP_APL_MAX_LEN 32
|
||||
#define APP_RENDER_CMD_MAX_LEN 2048
|
||||
#define APP_OWNER_ID_LEN 64
|
||||
|
||||
/* AppParameter.flags bit definition */
|
||||
#define APP_COLD_BOOT 0x01
|
||||
#define APP_BACKUP_EXTENSION 0x02
|
||||
#define APP_DLP_MANAGER 0x04
|
||||
#define APP_DEBUGGABLE 0x08 // debuggable application
|
||||
#define APP_ASANENABLED 0x10
|
||||
#define APP_ACCESS_BUNDLE_DIR 0x20
|
||||
#define APP_NATIVEDEBUG 0X40
|
||||
#define APP_NO_SANDBOX 0x80 // Do not enter sandbox
|
||||
#define APP_OVERLAY_FLAG 0x100
|
||||
#define GET_BUNDLE_RESOURCES_FLAG 0x200
|
||||
#define APP_GWP_ENABLED_FORCE 0x400
|
||||
#define APP_GWP_ENABLED_NORMAL 0x800
|
||||
#define APP_TSANENABLED 0x1000
|
||||
#define BITLEN32 32
|
||||
#define FDLEN2 2
|
||||
#define FD_INIT_VALUE 0
|
||||
|
||||
#define APPSPAWN_COLDSTART_KEY "cold-start"
|
||||
#define NWEBSPAWN_COLDSTART_KEY "nweb-cold-start"
|
||||
|
||||
typedef struct ExtraInfo {
|
||||
uint32_t totalLength;
|
||||
uint32_t savedLength;
|
||||
char* data;
|
||||
} ExtraInfo;
|
||||
|
||||
typedef struct AppParameter {
|
||||
AppOperateType code;
|
||||
uint32_t flags;
|
||||
int32_t pid; // query render process exited status by render process pid
|
||||
uint32_t uid; // the UNIX uid that the child process setuid() to after fork()
|
||||
uint32_t gid; // the UNIX gid that the child process setgid() to after fork()
|
||||
uint32_t gidCount; // the size of gidTable
|
||||
uint32_t gidTable[APP_MAX_GIDS]; // a list of UNIX gids that the child process setgroups() to after fork()
|
||||
char processName[APP_LEN_PROC_NAME]; // process name
|
||||
char bundleName[APP_LEN_BUNDLE_NAME]; // bundle name
|
||||
char soPath[APP_LEN_SO_PATH]; // so lib path
|
||||
char apl[APP_APL_MAX_LEN];
|
||||
char renderCmd[APP_RENDER_CMD_MAX_LEN];
|
||||
char ownerId[APP_OWNER_ID_LEN]; // app identifier id
|
||||
uint32_t accessTokenId;
|
||||
int32_t bundleIndex;
|
||||
uint64_t accessTokenIdEx;
|
||||
uint32_t hapFlags;
|
||||
uint32_t mountPermissionFlags;
|
||||
#ifndef OHOS_LITE
|
||||
uint8_t setAllowInternet;
|
||||
uint8_t allowInternet; // hap sockect allowed
|
||||
uint8_t reserved1;
|
||||
uint8_t reserved2;
|
||||
#endif
|
||||
ExtraInfo extraInfo; // Extera info using by format |type1|...|type1|type2|...|type2|
|
||||
} AppParameter;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,114 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef APPSPAWN_SOCKET_H
|
||||
#define APPSPAWN_SOCKET_H
|
||||
|
||||
#include <string>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppSpawn {
|
||||
class AppSpawnSocket {
|
||||
public:
|
||||
/**
|
||||
* Constructor used to delete the default constructor.
|
||||
*/
|
||||
AppSpawnSocket() = delete;
|
||||
|
||||
/**
|
||||
* Constructor used to create a AppSpawnSocket.
|
||||
*/
|
||||
explicit AppSpawnSocket(const std::string &name);
|
||||
|
||||
/**
|
||||
* Destructor used to destroy a AppSpawnSocket
|
||||
*/
|
||||
virtual ~AppSpawnSocket();
|
||||
|
||||
/**
|
||||
* Disables copying and moving for the AppSpawnSocket.
|
||||
*/
|
||||
DISALLOW_COPY_AND_MOVE(AppSpawnSocket);
|
||||
|
||||
/**
|
||||
* Gets the socket's file descriptor (FD).
|
||||
*/
|
||||
int GetSocketFd() const;
|
||||
|
||||
/**
|
||||
* Reads messages from the AppSpawn socket.
|
||||
*
|
||||
* @param socketFd Indicates the socket's FD.
|
||||
* @param buf Indicates the message buffer.
|
||||
* @param len Indicates the message size.
|
||||
*
|
||||
* @return -1:failed;other means message size.
|
||||
*/
|
||||
virtual int ReadSocketMessage(int socketFd, void *buf, int len);
|
||||
|
||||
/**
|
||||
* Writes messages to the AppSpawn socket.
|
||||
*
|
||||
* @param socketFd Indicates the socket's FD.
|
||||
* @param buf Indicates the message buffer.
|
||||
* @param len Indicates the message size.
|
||||
*
|
||||
* @return -1:failed;other means message size.
|
||||
*/
|
||||
virtual int WriteSocketMessage(int socketFd, const void *buf, int len);
|
||||
|
||||
/**
|
||||
* Closes an AppSpawn socket.
|
||||
*
|
||||
* @param socketFd Indicates the socket's FD.
|
||||
*/
|
||||
static void CloseSocket(int &socketFd);
|
||||
|
||||
/**
|
||||
* Creates an AppSpawn socket.
|
||||
*
|
||||
* @return -1:failed;other means connection FD.
|
||||
*/
|
||||
static int CreateSocket();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Sets the socket name to the socket address.
|
||||
*
|
||||
* @return -1:failed; 0:success
|
||||
*/
|
||||
int PackSocketAddr();
|
||||
|
||||
protected:
|
||||
int socketFd_ = -1;
|
||||
std::string socketName_ {};
|
||||
struct sockaddr_un socketAddr_ {};
|
||||
socklen_t socketAddrLen_ = 0;
|
||||
#ifdef __MUSL__
|
||||
const std::string socketDir_ = "/dev/unix/socket/";
|
||||
#else
|
||||
const std::string socketDir_ = "/dev/socket/";
|
||||
#endif
|
||||
const unsigned int listenBacklog_ = 50; // 50: max num of clients
|
||||
};
|
||||
} // namespace AppSpawn
|
||||
} // namespace OHOS
|
||||
#endif
|
@ -1,108 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef APPSPAWN_SOCKET_CLIENT_H
|
||||
#define APPSPAWN_SOCKET_CLIENT_H
|
||||
|
||||
#include "appspawn_socket.h"
|
||||
#include "appspawn_msg.h"
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppSpawn {
|
||||
class ClientSocket : public AppSpawnSocket {
|
||||
public:
|
||||
/**
|
||||
* Constructor used to create a ClientSocket
|
||||
*/
|
||||
explicit ClientSocket(const std::string &client);
|
||||
|
||||
/**
|
||||
* Destructor used to destroy a ClientSocket
|
||||
*/
|
||||
virtual ~ClientSocket() = default;
|
||||
|
||||
/**
|
||||
* Disables copying and moving for the ClientSocket.
|
||||
*/
|
||||
DISALLOW_COPY_AND_MOVE(ClientSocket);
|
||||
|
||||
/**
|
||||
* Creates a local client socket.
|
||||
*/
|
||||
virtual int CreateClient();
|
||||
|
||||
/**
|
||||
* Closes a client socket.
|
||||
*/
|
||||
virtual void CloseClient();
|
||||
|
||||
/**
|
||||
* Connects a client socket.
|
||||
*/
|
||||
virtual int ConnectSocket();
|
||||
|
||||
/**
|
||||
* Writes messages to a client socket.
|
||||
*
|
||||
* @param buf Indicates the pointer to the message buffer.
|
||||
* @param len Indicates the message length.
|
||||
*/
|
||||
virtual int WriteSocketMessage(const void *buf, int len);
|
||||
|
||||
/**
|
||||
* Reads messages from a client socket.
|
||||
*
|
||||
* @param buf Indicates the pointer to the message buffer.
|
||||
* @param len Indicates the message length.
|
||||
*/
|
||||
virtual int ReadSocketMessage(void *buf, int len);
|
||||
|
||||
/**
|
||||
* Uses functions of the parent class.
|
||||
*/
|
||||
using AppSpawnSocket::CloseSocket;
|
||||
using AppSpawnSocket::CreateSocket;
|
||||
using AppSpawnSocket::GetSocketFd;
|
||||
using AppSpawnSocket::ReadSocketMessage;
|
||||
using AppSpawnSocket::WriteSocketMessage;
|
||||
|
||||
enum AppType {
|
||||
APP_TYPE_DEFAULT = 0, // JavaScript app
|
||||
APP_TYPE_NATIVE // Native C++ app
|
||||
};
|
||||
|
||||
static constexpr int APPSPAWN_MSG_MAX_SIZE = APP_MSG_MAX_SIZE; // appspawn message max size
|
||||
static constexpr int LEN_PROC_NAME = APP_LEN_PROC_NAME; // process name length
|
||||
static constexpr int LEN_BUNDLE_NAME = APP_LEN_BUNDLE_NAME; // bundle name length
|
||||
static constexpr int LEN_SO_PATH = APP_LEN_SO_PATH; // load so lib
|
||||
static constexpr int MAX_GIDS = APP_MAX_GIDS;
|
||||
static constexpr int APL_MAX_LEN = APP_APL_MAX_LEN;
|
||||
static constexpr int RENDER_CMD_MAX_LEN = APP_RENDER_CMD_MAX_LEN;
|
||||
static constexpr int APPSPAWN_COLD_BOOT = APP_COLD_BOOT;
|
||||
|
||||
using AppProperty = AppParameter;
|
||||
using AppOperateCode = AppOperateType;
|
||||
private:
|
||||
/**
|
||||
* Connects a client socket.
|
||||
*
|
||||
* @param connectFd Indicates the connection's FD.
|
||||
*/
|
||||
int ConnectSocket(int connectFd);
|
||||
};
|
||||
} // namespace AppSpawn
|
||||
} // namespace OHOS
|
||||
#endif
|
@ -1,115 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2023 Huawei Device Co., Ltd.
|
||||
* 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 <fstream>
|
||||
#include <sstream>
|
||||
#include "appspawn_mount_permission.h"
|
||||
#include "appspawn_server.h"
|
||||
#include "config_policy_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppSpawn {
|
||||
namespace {
|
||||
const std::string APP_PERMISSION_PATH("/appdata-sandbox.json");
|
||||
const std::string PERMISSION_FIELD("permission");
|
||||
}
|
||||
std::set<std::string> AppspawnMountPermission::appSandboxPremission_ = {};
|
||||
bool AppspawnMountPermission::isLoad_ = false;
|
||||
std::mutex AppspawnMountPermission::mutex_;
|
||||
|
||||
void AppspawnMountPermission::GetPermissionFromJson(
|
||||
std::set<std::string> &appSandboxPremissionSet, nlohmann::json &appSandboxPremission)
|
||||
{
|
||||
auto item = appSandboxPremission.find(PERMISSION_FIELD);
|
||||
if (item != appSandboxPremission.end()) {
|
||||
for (auto config : appSandboxPremission[PERMISSION_FIELD]) {
|
||||
for (auto it : config.items()) {
|
||||
APPSPAWN_LOGI("LoadPermissionNames %{public}s", it.key().c_str());
|
||||
appSandboxPremissionSet.insert(it.key());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
APPSPAWN_LOGI("permission does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
void AppspawnMountPermission::LoadPermissionNames(void)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (isLoad_) {
|
||||
return;
|
||||
}
|
||||
appSandboxPremission_.clear();
|
||||
nlohmann::json appSandboxPremission;
|
||||
CfgFiles *files = GetCfgFiles("etc/sandbox");
|
||||
for (int i = 0; (files != nullptr) && (i < MAX_CFG_POLICY_DIRS_CNT); ++i) {
|
||||
if (files->paths[i] == nullptr) {
|
||||
continue;
|
||||
}
|
||||
std::string path = files->paths[i];
|
||||
path += APP_PERMISSION_PATH;
|
||||
APPSPAWN_LOGI("LoadAppSandboxConfig %{public}s", path.c_str());
|
||||
std::ifstream jsonFileStream;
|
||||
jsonFileStream.open(path.c_str(), std::ios::in);
|
||||
APPSPAWN_CHECK_ONLY_EXPER(jsonFileStream.is_open(), return);
|
||||
std::stringstream buffer;
|
||||
buffer << jsonFileStream.rdbuf();
|
||||
appSandboxPremission = nlohmann::json::parse(buffer.str(), nullptr, false);
|
||||
APPSPAWN_CHECK(appSandboxPremission.is_structured(), return, "Parse json file into jsonObj failed.");
|
||||
GetPermissionFromJson(appSandboxPremission_, appSandboxPremission);
|
||||
}
|
||||
FreeCfgFiles(files);
|
||||
APPSPAWN_LOGI("LoadPermissionNames size: %{public}lu", static_cast<unsigned long>(appSandboxPremission_.size()));
|
||||
isLoad_ = true;
|
||||
}
|
||||
|
||||
std::set<std::string> AppspawnMountPermission::GetMountPermissionList()
|
||||
{
|
||||
if (!isLoad_) {
|
||||
LoadPermissionNames();
|
||||
APPSPAWN_LOGV("GetMountPermissionList LoadPermissionNames");
|
||||
}
|
||||
return appSandboxPremission_;
|
||||
}
|
||||
|
||||
uint32_t AppspawnMountPermission::GenPermissionCode(const std::set<std::string> &permissions)
|
||||
{
|
||||
uint32_t result = 0;
|
||||
if (permissions.size() == 0) {
|
||||
return result;
|
||||
}
|
||||
uint32_t flagIndex = 1;
|
||||
for (std::string mountPermission : GetMountPermissionList()) {
|
||||
for (std::string inputPermission : permissions) {
|
||||
if (mountPermission.compare(inputPermission) == 0) {
|
||||
result |= flagIndex;
|
||||
}
|
||||
}
|
||||
flagIndex <<= 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool AppspawnMountPermission::IsMountPermission(uint32_t code, const std::string permission)
|
||||
{
|
||||
for (std::string mountPermission : GetMountPermissionList()) {
|
||||
if (mountPermission.compare(permission) == 0) {
|
||||
return code & 1;
|
||||
}
|
||||
code >>= 1;
|
||||
}
|
||||
return false;
|
||||
} // AppSpawn
|
||||
} // OHOS
|
||||
}
|
@ -21,9 +21,9 @@ ohos_fuzztest("AppSpawnClientFuzzTest") {
|
||||
module_out_path = module_output_path
|
||||
fuzz_config_file = "${appspawn_path}/test/fuzztest/appspawnclient_fuzzer"
|
||||
|
||||
include_dirs = [ "${appspawn_path}/interfaces/innerkits_new/include" ]
|
||||
include_dirs = [ "${appspawn_path}/interfaces/innerkits/include" ]
|
||||
|
||||
deps = [ "${appspawn_path}/interfaces/innerkits_new/client:appspawn_client" ]
|
||||
deps = [ "${appspawn_path}/interfaces/innerkits/client:appspawn_client" ]
|
||||
external_deps = [ "bounds_checking_function:libsec_static" ]
|
||||
|
||||
defines = []
|
||||
|
@ -24,7 +24,6 @@
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "appspawn_message.h"
|
||||
#include "appspawn_msg.h"
|
||||
#include "appspawn_service.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
|
Loading…
Reference in New Issue
Block a user