From e24c8bdd74edbc4a1aa4426580df4b3f40d42852 Mon Sep 17 00:00:00 2001 From: zhouzhichao Date: Fri, 9 Dec 2022 17:54:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8EHOS=E5=90=8C=E6=AD=A5=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=96=87=E4=BB=B6=E7=AD=89=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhouzhichao --- .../kits/js/src/mod_securitylabel/security_label.h | 3 --- .../src/mod_securitylabel/securitylabel_n_exporter.cpp | 9 +++++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/interfaces/kits/js/src/mod_securitylabel/security_label.h b/interfaces/kits/js/src/mod_securitylabel/security_label.h index 5e47c8be9..6610f0fd9 100644 --- a/interfaces/kits/js/src/mod_securitylabel/security_label.h +++ b/interfaces/kits/js/src/mod_securitylabel/security_label.h @@ -32,9 +32,6 @@ class SecurityLabel { public: static bool SetSecurityLabel(const std::string &path, const std::string &dataLevel) { - if (DATA_LEVEL.count(dataLevel) != 1) { - return false; - } if (setxattr(path.c_str(), XATTR_KEY, dataLevel.c_str(), dataLevel.size(), 0) < 0) { return false; } diff --git a/interfaces/kits/js/src/mod_securitylabel/securitylabel_n_exporter.cpp b/interfaces/kits/js/src/mod_securitylabel/securitylabel_n_exporter.cpp index 88ee86e83..d3910a013 100644 --- a/interfaces/kits/js/src/mod_securitylabel/securitylabel_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_securitylabel/securitylabel_n_exporter.cpp @@ -58,6 +58,7 @@ napi_value SetSecurityLabel(napi_env env, napi_callback_info info) UniError(EINVAL).ThrowErr(env, "Invalid Argument of dataLevelEnum"); return nullptr; } + std::transform(dataLevelString.begin(), dataLevelString.end(), dataLevelString.begin(), ::toupper); auto cbExec = [pathString, dataLevelString](napi_env env) -> UniError { bool ret = SecurityLabel::SetSecurityLabel(pathString, dataLevelString); if (!ret) { @@ -108,13 +109,15 @@ napi_value SetSecurityLabelSync(napi_env env, napi_callback_info info) UniError(EINVAL).ThrowErr(env, "Invalid dataLevel"); return nullptr; } - + std::string pathString(path.get()); + std::string dataLevelString(dataLevel.get()); if (DATA_LEVEL.find(dataLevel.get()) == DATA_LEVEL.end()) { UniError(EINVAL).ThrowErr(env, "Invalid Argument of dataLevelEnum"); return nullptr; } - bool ret = SecurityLabel::SetSecurityLabel(path.get(), dataLevel.get()); + std::transform(dataLevelString.begin(), dataLevelString.end(), dataLevelString.begin(), ::toupper); + bool ret = SecurityLabel::SetSecurityLabel(pathString, dataLevelString); if (!ret) { return UniError(errno).GetNapiErr(env); } @@ -147,6 +150,7 @@ napi_value GetSecurityLabel(napi_env env, napi_callback_info info) if (err) { return { env, err.GetNapiErr(env) }; } + std::transform((*result).begin(), (*result).end(), (*result).begin(), ::tolower); return { NVal::CreateUTF8String(env, *result) }; }; @@ -180,6 +184,7 @@ napi_value GetSecurityLabelSync(napi_env env, napi_callback_info info) } std::string result = SecurityLabel::GetSecurityLabel(path.get()); + std::transform(result.begin(), result.end(), result.begin(), ::tolower); return NVal::CreateUTF8String(env, result).val_; } } // namespace ModuleSecurityLabel -- Gitee