提交 3d01c25c 编写于 作者: Z zhangqilong 提交者: Qilong Zhang

fscrypt:fix init unittest compile failed

Signed-off-by: Nzhangqilong <zhangqilong3@huawei.com>
Change-Id: I1d4def8c08dd4f54ae48191340c4c36ba319b8a8
上级 9b27d151
......@@ -42,11 +42,7 @@ struct MountFlags {
unsigned long flags;
};
#define POLICY_BUFFER (100)
static const char *g_fscryptPre = "fscrypt=";
static const char *g_mountPoint = "/data";
static char g_fscryptPolicy[POLICY_BUFFER] = { 0 };
static char *g_fscryptPolicy = NULL;
static unsigned int ConvertFlags(char *flagBuffer)
{
......@@ -392,10 +388,12 @@ static unsigned long ParseDefaultMountFlag(const char *str)
static bool IsFscryptOption(const char *option)
{
BEGET_LOGI("IsFscryptOption start");
if (!option) {
return false;
}
if (strncmp(option, g_fscryptPre, strlen(g_fscryptPre)) == 0) {
char *fscryptPre = "fscrypt=";
if (strncmp(option, fscryptPre, strlen(fscryptPre)) == 0) {
return true;
}
return false;
......@@ -403,23 +401,41 @@ static bool IsFscryptOption(const char *option)
static void StoreFscryptPolicy(const char *option)
{
if (!option) {
if (option == NULL) {
return;
}
if (strcpy_s(g_fscryptPolicy, POLICY_BUFFER - 1, option) != EOK) {
g_fscryptPolicy[0] = '\0';
BEGET_LOGE("StoreFscryptPolicy: copy policy failed");
if (g_fscryptPolicy != NULL) {
BEGET_LOGW("StoreFscryptPolicy:inited policy is not empty");
free(g_fscryptPolicy);
}
g_fscryptPolicy = strdup(option);
if (g_fscryptPolicy == NULL) {
BEGET_LOGE("StoreFscryptPolicy:no memory");
return;
}
BEGET_LOGI("StoreFscryptPolicy:load fscrypt policy, %s", option);
BEGET_LOGI("StoreFscryptPolicy:store fscrypt policy, %s", option);
}
const char *LoadFscryptPolicy(void)
int LoadFscryptPolicy(char *buf, size_t size)
{
if (strnlen(g_fscryptPolicy, POLICY_BUFFER - 1) == 0) {
return NULL;
BEGET_LOGI("LoadFscryptPolicy start");
if (buf == NULL || g_fscryptPolicy == NULL) {
BEGET_LOGE("LoadFscryptPolicy:buf or fscrypt policy is empty");
return -ENOMEM;
}
return g_fscryptPolicy;
if (size <= 0) {
BEGET_LOGE("LoadFscryptPloicy:size is invalid");
return -EINVAL;
}
if (strcpy_s(buf, size, g_fscryptPolicy) != 0) {
BEGET_LOGE("loadFscryptPolicy:strcmp failed, error = %d", errno);
return -EFAULT;
}
free(g_fscryptPolicy);
g_fscryptPolicy = NULL;
BEGET_LOGI("LoadFscryptPolicy success");
return 0;
}
unsigned long GetMountFlags(char *mountFlag, char *fsSpecificData, size_t fsSpecificDataSize,
......@@ -448,8 +464,8 @@ unsigned long GetMountFlags(char *mountFlag, char *fsSpecificData, size_t fsSpec
flags |= ParseDefaultMountFlag(p);
} else {
if (IsFscryptOption(p) &&
!strncmp(mountPoint, g_mountPoint, strlen(g_mountPoint))) {
StoreFscryptPolicy(p + strlen(g_fscryptPre));
!strncmp(mountPoint, "/data", strlen("/data"))) {
StoreFscryptPolicy(p + strlen("fscrypt="));
continue;
}
if (strncat_s(fsSpecificData, fsSpecificDataSize - 1, p, strlen(p)) != EOK) {
......
......@@ -76,7 +76,7 @@ unsigned long GetMountFlags(char *mountFlag, char *fsSpecificFlags, size_t fsSpe
int GetBlockDevicePath(const char *partName, char *path, int size);
// Get fscrypt policy if exist
const char *LoadFscryptPolicy(void);
int LoadFscryptPolicy(char *buf, size_t size);
#ifdef __cplusplus
#if __cplusplus
}
......
......@@ -46,6 +46,7 @@
#endif
#include "fscrypt_utils.h"
#define FSCRYPT_POLICY_BUF_SIZE (60)
int GetParamValue(const char *symValue, unsigned int symLen, char *paramValue, unsigned int paramLen)
{
......@@ -414,8 +415,8 @@ static void DoTimerStop(const struct CmdArgs *ctx)
static bool InitFscryptPolicy(void)
{
const char *policy = LoadFscryptPolicy();
if (!policy) {
char policy[FSCRYPT_POLICY_BUF_SIZE];
if (LoadFscryptPolicy(policy, FSCRYPT_POLICY_BUF_SIZE) != 0) {
return false;
}
if (SetFscryptSysparam(policy) == 0) {
......@@ -436,9 +437,8 @@ static void DoInitGlobalKey(const struct CmdArgs *ctx)
INIT_LOGE("DoInitGlobalKey: not data partitation");
return;
}
if (!InitFscryptPolicy()) {
INIT_LOGE("DoInitGlobalKey: init policy failed");
INIT_LOGI("DoInitGlobalKey:init fscrypt failed,not enable fscrypt");
return;
}
......@@ -460,10 +460,6 @@ static void DoInitMainUser(const struct CmdArgs *ctx)
INIT_LOGE("DoInitMainUser: para invalid");
return;
}
if (LoadFscryptPolicy() == NULL) {
INIT_LOGI("DoInitMainUser: file crypto is not enabled");
return;
}
char * const argv[] = {
"/system/bin/sdc",
......@@ -604,7 +600,6 @@ void OpenHidebug(const char *name)
int SetFileCryptPolicy(const char *dir)
{
INIT_LOGI("SetFileCryptPolicy:start:%s", dir);
if (dir == NULL) {
INIT_LOGE("SetFileCryptPolicy:dir is null");
return -EINVAL;
......
......@@ -108,6 +108,13 @@ ohos_unittest("init_unittest") {
"//base/startup/init/ueventd/ueventd_socket.c",
]
sources += [
"${FSCRYPT_PATH}/libfscrypt/src/fscrypt_control.c",
"${FSCRYPT_PATH}/libfscrypt/src/fscrypt_utils.c",
"${FSCRYPT_PATH}/libfscrypt/src/key_control.c",
"${FSCRYPT_PATH}/libfscrypt/src/sysparam_static.c",
]
if (defined(build_selinux) && build_selinux) {
sources += [ "//base/startup/init/services/param/adapter/param_selinux.c" ]
}
......@@ -216,8 +223,6 @@ ohos_unittest("init_unittest") {
"//utils/native/base:utils",
]
deps += [ "${FSCRYPT_PATH}/libfscrypt:libfscryptutils_static" ]
defines = [
"READ_CHECK",
"INIT_AGENT",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册