From 2b693b8df232f3cfa10ce62105265ba9d3929359 Mon Sep 17 00:00:00 2001 From: guolongfei Date: Sun, 7 Sep 2025 02:09:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=91=E5=8D=95master=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=88=B0Release-6.0=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: guolongfei --- common/native/include/edm_constants.h | 3 +- interfaces/inner_api/BUILD.gn | 1 + .../src/application_manager_proxy.cpp | 1 - .../common/include/edm_ipc_interface_code.h | 2 +- .../network_manager/include/network_address.h | 60 +++++++++---------- .../plugin_kits/include/iplugin_template.tpp | 1 - .../src/utils/array_int_serializer.cpp | 1 - .../src/system_manager_proxy.cpp | 1 - interfaces/kits/bluetooth_manager/BUILD.gn | 3 +- .../src/bluetooth_manager_addon.cpp | 2 + .../kits/browser/include/browser_addon.h | 1 + interfaces/kits/browser/src/browser_addon.cpp | 2 +- interfaces/kits/network_manager/BUILD.gn | 2 +- .../include/network_manager_addon.h | 11 ++-- .../src/network_manager_addon.cpp | 46 +++++++++----- .../wifi_manager/src/wifi_manager_addon.cpp | 5 ++ .../disable_maintenance_mode_query.h | 4 +- .../edm/src/enterprise_device_mgr_ability.cpp | 23 +++---- .../allowed_bluetooth_devices_query.cpp | 1 - .../disallowed_mobile_data_query.cpp | 2 + services/edm/src/user_policy_manager.cpp | 4 +- services/edm_plugin/BUILD.gn | 3 +- ...lugin.h => get_ip_or_mac_address_plugin.h} | 10 ++-- .../src/allowed_usb_devices_plugin.cpp | 8 +-- .../src/disallow_mobile_data_plugin.cpp | 19 ++++-- ...n.cpp => get_ip_or_mac_address_plugin.cpp} | 22 ++++--- services/edm_plugin/src/get_mac_plugin.cpp | 59 ------------------ services/edm_plugin/src/install_plugin.cpp | 1 - services/edm_plugin/src/utils/apn_utils.cpp | 25 ++++++-- .../src/utils/bluetooth_config_utils.cpp | 1 + .../src/utils/nearlink_config_utils.cpp | 9 ++- .../src/utils/wifi_policy_utils.cpp | 3 + test/fuzztest/common/src/common_fuzzer.cpp | 10 ++-- .../BUILD.gn | 3 +- test/unittest/services/edm/BUILD.gn | 1 + .../enterprise_device_mgr_ability_test.cpp | 12 ++-- test/unittest/services/edm_plugin/BUILD.gn | 4 +- .../src/network_manager_plugin_test.cpp | 10 ++-- 38 files changed, 181 insertions(+), 195 deletions(-) rename services/edm_plugin/include/get_mac_plugin.h => interfaces/inner_api/network_manager/include/network_address.h (53%) rename services/edm_plugin/include/{get_ip_address_plugin.h => get_ip_or_mac_address_plugin.h} (65%) rename services/edm_plugin/src/{get_ip_address_plugin.cpp => get_ip_or_mac_address_plugin.cpp} (72%) delete mode 100644 services/edm_plugin/src/get_mac_plugin.cpp diff --git a/common/native/include/edm_constants.h b/common/native/include/edm_constants.h index 0ed053972..6307ad3e2 100644 --- a/common/native/include/edm_constants.h +++ b/common/native/include/edm_constants.h @@ -307,8 +307,7 @@ namespace PolicyName { const char* const POLICY_GET_NETWORK_INTERFACES = "get_network_interfaces"; const char* const POLICY_GET_BLUETOOTH_INFO = "get_bluetooth_info"; const char* const POLICY_GET_DEVICE_INFO = "get_device_info"; - const char* const POLICY_GET_IP_ADDRESS = "get_ip_address"; - const char* const POLICY_GET_MAC = "get_mac"; + const char* const POLICY_GET_IP_OR_MAC_ADDRESS = "get_ip_or_mac_address"; const char* const POLICY_GLOBAL_PROXY = "global_proxy"; const char* const POLICY_INACTIVE_USER_FREEZE = "inactive_user_freeze"; const char* const POLICY_INSTALL = "install"; diff --git a/interfaces/inner_api/BUILD.gn b/interfaces/inner_api/BUILD.gn index 1605ebe33..68e375ed9 100644 --- a/interfaces/inner_api/BUILD.gn +++ b/interfaces/inner_api/BUILD.gn @@ -77,6 +77,7 @@ ohos_shared_library("edmservice_kits") { "./wifi_manager/src/wifi_manager_proxy.cpp", "./telephony_manager/src/telephony_manager_proxy.cpp", "./telephony_manager/src/telephony_call_policy_serializer.cpp", + "../../common/native/src/edm_utils.cpp" ] innerapi_tags = [ "platformsdk" ] diff --git a/interfaces/inner_api/application_manager/src/application_manager_proxy.cpp b/interfaces/inner_api/application_manager/src/application_manager_proxy.cpp index 9bc08046f..48c9a4b43 100644 --- a/interfaces/inner_api/application_manager/src/application_manager_proxy.cpp +++ b/interfaces/inner_api/application_manager/src/application_manager_proxy.cpp @@ -293,7 +293,6 @@ int32_t ApplicationManagerProxy::IsAppKioskAllowed(const std::string &appIdentif return ERR_OK; } - int32_t ApplicationManagerProxy::ClearUpApplicationData( const AppExecFwk::ElementName &admin, const ClearUpApplicationDataParam ¶m) { diff --git a/interfaces/inner_api/common/include/edm_ipc_interface_code.h b/interfaces/inner_api/common/include/edm_ipc_interface_code.h index 7c063922b..51542b843 100644 --- a/interfaces/inner_api/common/include/edm_ipc_interface_code.h +++ b/interfaces/inner_api/common/include/edm_ipc_interface_code.h @@ -154,7 +154,7 @@ enum EdmInterfaceCode : uint32_t { DISALLOWED_TELEPHONY_CALL = 1109, DISALLOWED_NEARLINK_PROTOCOLS = 1110, DISABLE_PRIVATE_SPACE = 1111, - DISALLOWED_EXPORT_RECOVERY_KEY = 1112, + DISALLOWED_EXPORT_RECOVERY_KEY = 1112, DISABLED_PRINT = 1113, PERMISSION_MANAGED_STATE = 1114, SET_WALL_PAPER = 1115, diff --git a/services/edm_plugin/include/get_mac_plugin.h b/interfaces/inner_api/network_manager/include/network_address.h similarity index 53% rename from services/edm_plugin/include/get_mac_plugin.h rename to interfaces/inner_api/network_manager/include/network_address.h index 1706fff76..0d73916f8 100644 --- a/services/edm_plugin/include/get_mac_plugin.h +++ b/interfaces/inner_api/network_manager/include/network_address.h @@ -1,32 +1,28 @@ -/* - * Copyright (c) 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 SERVICES_EDM_PLUGIN_INCLUDE_GET_MAC_PLUGIN_H -#define SERVICES_EDM_PLUGIN_INCLUDE_GET_MAC_PLUGIN_H - -#include "plugin_singleton.h" - -namespace OHOS { -namespace EDM { -class GetMacPlugin : public PluginSingleton { -public: - void InitPlugin(std::shared_ptr> ptr) override; - - ErrCode OnGetPolicy(std::string &policyData, MessageParcel &data, MessageParcel &reply, int32_t userId) override; -}; -} // namespace EDM -} // namespace OHOS - -#endif // SERVICES_EDM_PLUGIN_INCLUDE_GET_MAC_PLUGIN_H +/* + * Copyright (c) 2025-2025 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 INTERFACES_INNER_API_NETWORK_MANAGER_INCLUDE_NETWORK_ADDRESS_H +#define INTERFACES_INNER_API_NETWORK_MANAGER_INCLUDE_NETWORK_ADDRESS_H + +namespace OHOS { +namespace EDM { +enum NetworkAddress : int32_t { + IPADDRESS = 0, + MAC = 1 +}; +} // namespace EDM +} // namespace OHOS + +#endif // INTERFACES_INNER_API_NETWORK_MANAGER_INCLUDE_NETWORK_ADDRESS_H \ No newline at end of file diff --git a/interfaces/inner_api/plugin_kits/include/iplugin_template.tpp b/interfaces/inner_api/plugin_kits/include/iplugin_template.tpp index ede6fa956..1f9d1c19d 100644 --- a/interfaces/inner_api/plugin_kits/include/iplugin_template.tpp +++ b/interfaces/inner_api/plugin_kits/include/iplugin_template.tpp @@ -303,7 +303,6 @@ void IPluginTemplate::SetOnAdminRemoveListener(BiAdminFunction &&listene } auto adminRemove = [this](const std::string &adminName, const std::string ¤tJsonData, const std::string &mergeJsonData, int32_t userId) -> ErrCode { - EDMLOGI("currentJsonData = %{public}s, mergeJsonData=%{public}s", currentJsonData.c_str(), mergeJsonData.c_str()); DT currentData; if (!serializer_->Deserialize(currentJsonData, currentData)) { return ERR_EDM_OPERATE_JSON; diff --git a/interfaces/inner_api/plugin_kits/src/utils/array_int_serializer.cpp b/interfaces/inner_api/plugin_kits/src/utils/array_int_serializer.cpp index de38831a9..bd7e1ef7e 100644 --- a/interfaces/inner_api/plugin_kits/src/utils/array_int_serializer.cpp +++ b/interfaces/inner_api/plugin_kits/src/utils/array_int_serializer.cpp @@ -16,7 +16,6 @@ #include "array_int_serializer.h" #include "cJSON.h" #include "cjson_check.h" -#include "edm_constants.h" namespace OHOS { namespace EDM { diff --git a/interfaces/inner_api/system_manager/src/system_manager_proxy.cpp b/interfaces/inner_api/system_manager/src/system_manager_proxy.cpp index c99c23642..b20d1c9db 100644 --- a/interfaces/inner_api/system_manager/src/system_manager_proxy.cpp +++ b/interfaces/inner_api/system_manager/src/system_manager_proxy.cpp @@ -195,7 +195,6 @@ int32_t SystemManagerProxy::GetInstallLocalEnterpriseAppEnabled(MessageParcel &d return ERR_OK; } - int32_t SystemManagerProxy::AddOrRemoveDisallowedNearlinkProtocols(MessageParcel &data, FuncOperateType operateType) { EDMLOGD("SystemManagerProxy::AddOrRemoveDisallowedNearlinkProtocols"); diff --git a/interfaces/kits/bluetooth_manager/BUILD.gn b/interfaces/kits/bluetooth_manager/BUILD.gn index 521a1ac14..772c250ca 100644 --- a/interfaces/kits/bluetooth_manager/BUILD.gn +++ b/interfaces/kits/bluetooth_manager/BUILD.gn @@ -20,7 +20,8 @@ ohos_shared_library("bluetoothmanager") { ] sources = [ - "./src/bluetooth_manager_addon.cpp" + "./src/bluetooth_manager_addon.cpp", + "../../../common/native/src/edm_utils.cpp" ] configs = [ "../../../common/config:coverage_flags" ] diff --git a/interfaces/kits/bluetooth_manager/src/bluetooth_manager_addon.cpp b/interfaces/kits/bluetooth_manager/src/bluetooth_manager_addon.cpp index 8c73f65b3..fbe038227 100644 --- a/interfaces/kits/bluetooth_manager/src/bluetooth_manager_addon.cpp +++ b/interfaces/kits/bluetooth_manager/src/bluetooth_manager_addon.cpp @@ -17,6 +17,7 @@ #include "edm_constants.h" #include "edm_log.h" +#include "edm_utils.h" #include "errors.h" #include "js_native_api.h" #include "napi_edm_adapter.h" @@ -174,6 +175,7 @@ napi_value BluetoothManagerAddon::GetBluetoothDevices(napi_env env, napi_callbac for (size_t i = 0; i < deviceIds.size(); i++) { napi_value allowedDevices = nullptr; NAPI_CALL(env, napi_create_string_utf8(env, deviceIds[i].c_str(), NAPI_AUTO_LENGTH, &allowedDevices)); + EdmUtils::ClearString(deviceIds[i]); NAPI_CALL(env, napi_set_element(env, result, i, allowedDevices)); } return result; diff --git a/interfaces/kits/browser/include/browser_addon.h b/interfaces/kits/browser/include/browser_addon.h index f0a2a5a71..272b51b88 100644 --- a/interfaces/kits/browser/include/browser_addon.h +++ b/interfaces/kits/browser/include/browser_addon.h @@ -31,6 +31,7 @@ struct AsyncBrowserCallbackInfo : AsyncCallbackInfo { std::string policies; napi_value value; }; +constexpr int32_t MAX_POLICY_FILE_SIZE = 134217728; // 128*1024*1024 class BrowserAddon { public: diff --git a/interfaces/kits/browser/src/browser_addon.cpp b/interfaces/kits/browser/src/browser_addon.cpp index 8329cf36f..b0c80a8ff 100644 --- a/interfaces/kits/browser/src/browser_addon.cpp +++ b/interfaces/kits/browser/src/browser_addon.cpp @@ -343,7 +343,7 @@ napi_value BrowserAddon::CreateArrayBuffer(napi_env env, void* data, int32_t siz napi_throw(env, CreateError(env, EdmReturnErrCode::SYSTEM_ABNORMALLY)); return nullptr; } - if (size < 0) { + if (size < 0 || size > MAX_POLICY_FILE_SIZE) { EDMLOGE("BrowserAddon::CreateArrayBuffer size error.size:%{public}d", size); napi_throw(env, CreateError(env, EdmReturnErrCode::SYSTEM_ABNORMALLY)); return nullptr; diff --git a/interfaces/kits/network_manager/BUILD.gn b/interfaces/kits/network_manager/BUILD.gn index 41bf1ecbb..ac33eca1d 100644 --- a/interfaces/kits/network_manager/BUILD.gn +++ b/interfaces/kits/network_manager/BUILD.gn @@ -57,7 +57,7 @@ ohos_shared_library("networkmanager") { if (!enterprise_device_management_feature_pc_only && cellular_data_edm_enable) { defines += [ "CELLULAR_DATA_EDM_ENABLE" ] } - + relative_install_dir = "module/enterprise" sanitize = { boundary_sanitize = true diff --git a/interfaces/kits/network_manager/include/network_manager_addon.h b/interfaces/kits/network_manager/include/network_manager_addon.h index 84dfe2306..40eaedde8 100644 --- a/interfaces/kits/network_manager/include/network_manager_addon.h +++ b/interfaces/kits/network_manager/include/network_manager_addon.h @@ -46,7 +46,9 @@ private: static napi_value GetAllNetworkInterfaces(napi_env env, napi_callback_info info); static napi_value GetIpAddress(napi_env env, napi_callback_info info); static napi_value GetMac(napi_env env, napi_callback_info info); - static napi_value GetIpOrMacAddress(napi_env env, napi_callback_info info, int policyCode); + static napi_value GetIpOrMacAddress(napi_env env, napi_callback_info info, int32_t networkAddress); + static void NativeGetIpAddress(napi_env env, void *data); + static void NativeGetMac(napi_env env, void *data); static napi_value SetNetworkInterfaceDisabled(napi_env env, napi_callback_info info); static napi_value IsNetworkInterfaceDisabled(napi_env env, napi_callback_info info); static napi_value AddIptablesFilterRule(napi_env env, napi_callback_info info); @@ -59,7 +61,7 @@ private: static napi_value RemoveDomainFilterRule(napi_env env, napi_callback_info info); static napi_value GetDomainFilterRules(napi_env env, napi_callback_info info); static void NativeGetAllNetworkInterfaces(napi_env env, void *data); - static void NativeGetIpOrMacAddress(napi_env env, void *data); + static void NativeGetIpOrMacAddress(napi_env env, void *data, int32_t networkAddress); static void NativeSetNetworkInterfaceDisabled(napi_env env, void *data); static void NativeIsNetworkInterfaceDisabled(napi_env env, void *data); static void NativeAddIptalbsFilterRule(napi_env env, void *data); @@ -92,7 +94,7 @@ private: static napi_value GetAllNetworkInterfacesSync(napi_env env, napi_callback_info info); static napi_value GetIpAddressSync(napi_env env, napi_callback_info info); static napi_value GetMacSync(napi_env env, napi_callback_info info); - static napi_value GetIpOrMacAddressSync(napi_env env, napi_callback_info info, int policyCode); + static napi_value GetIpOrMacAddressSync(napi_env env, napi_callback_info info, int32_t networkAddress); static napi_value SetNetworkInterfaceDisabledSync(napi_env env, napi_callback_info info); static napi_value IsNetworkInterfaceDisabledSync(napi_env env, napi_callback_info info); static napi_value SetGlobalHttpProxySync(napi_env env, napi_callback_info info); @@ -104,8 +106,7 @@ private: static napi_value GetGlobalHttpProxyCommon(napi_env env, napi_value *argv, size_t argc, bool hasAdmin, OHOS::AppExecFwk::ElementName &elementName, int32_t accountId); static void SetNetworkInterfaceDisabledCommon(AddonMethodSign &addonMethodSign, const std::string &apiVersionTag); - static void GetIpOrMacAddressCommon(AddonMethodSign &addonMethodSign, const std::string &apiVersionTag, - int32_t policyCode); + static void GetIpOrMacAddressCommon(AddonMethodSign &addonMethodSign, const std::string &apiVersionTag); static void IsNetworkInterfaceDisabledCommon(AddonMethodSign &addonMethodSign, const std::string &apiVersionTag); static void SetGlobalHttpProxyCommon(AddonMethodSign &addonMethodSign); static void SetGlobalHttpProxyCommonForAccount(AddonMethodSign &addonMethodSign); diff --git a/interfaces/kits/network_manager/src/network_manager_addon.cpp b/interfaces/kits/network_manager/src/network_manager_addon.cpp index 797df02b0..96d5ce2e9 100644 --- a/interfaces/kits/network_manager/src/network_manager_addon.cpp +++ b/interfaces/kits/network_manager/src/network_manager_addon.cpp @@ -18,7 +18,7 @@ #include "edm_ipc_interface_code.h" #include "edm_log.h" #include "iptables_utils.h" -#include "os_account_manager.h" +#include "network_address.h" using namespace OHOS::EDM; using namespace OHOS::EDM::IPTABLES; @@ -198,36 +198,47 @@ void NetworkManagerAddon::NativeGetAllNetworkInterfaces(napi_env env, void *data asyncCallbackInfo->arrayStringRet); } -void NetworkManagerAddon::GetIpOrMacAddressCommon(AddonMethodSign &addonMethodSign, const std::string &apiVersionTag, - int32_t policyCode) +void NetworkManagerAddon::GetIpOrMacAddressCommon(AddonMethodSign &addonMethodSign, const std::string &apiVersionTag) { addonMethodSign.name = "GetIpOrMacAddress"; addonMethodSign.argsType = {EdmAddonCommonType::ELEMENT, EdmAddonCommonType::STRING}; addonMethodSign.methodAttribute = MethodAttribute::GET; addonMethodSign.apiVersionTag = apiVersionTag; - addonMethodSign.policyCode = policyCode; } napi_value NetworkManagerAddon::GetIpAddress(napi_env env, napi_callback_info info) { EDMLOGI("NetworkManagerAddon::GetIpAddress called"); - return GetIpOrMacAddress(env, info, EdmInterfaceCode::GET_IP_ADDRESS); + return GetIpOrMacAddress(env, info, NetworkAddress::IPADDRESS); } napi_value NetworkManagerAddon::GetMac(napi_env env, napi_callback_info info) { EDMLOGI("NetworkManagerAddon::GetMac called"); - return GetIpOrMacAddress(env, info, EdmInterfaceCode::GET_MAC); + return GetIpOrMacAddress(env, info, NetworkAddress::MAC); } -napi_value NetworkManagerAddon::GetIpOrMacAddress(napi_env env, napi_callback_info info, int policyCode) +napi_value NetworkManagerAddon::GetIpOrMacAddress(napi_env env, napi_callback_info info, int32_t networkAddress) { AddonMethodSign addonMethodSign; - GetIpOrMacAddressCommon(addonMethodSign, EdmConstants::PERMISSION_TAG_VERSION_11, policyCode); - return AddonMethodAdapter(env, info, addonMethodSign, NativeGetIpOrMacAddress, NativeStringCallbackComplete); + GetIpOrMacAddressCommon(addonMethodSign, EdmConstants::PERMISSION_TAG_VERSION_11); + if (networkAddress == NetworkAddress::IPADDRESS) { + return AddonMethodAdapter(env, info, addonMethodSign, NativeGetIpAddress, NativeStringCallbackComplete); + } + return AddonMethodAdapter(env, info, addonMethodSign, NativeGetMac, NativeStringCallbackComplete); +} + +void NetworkManagerAddon::NativeGetIpAddress(napi_env env, void *data) +{ + NativeGetIpOrMacAddress(env, data, NetworkAddress::IPADDRESS); +} + +void NetworkManagerAddon::NativeGetMac(napi_env env, void *data) +{ + NativeGetIpOrMacAddress(env, data, NetworkAddress::MAC); } -void NetworkManagerAddon::NativeGetIpOrMacAddress(napi_env env, void *data) +void NetworkManagerAddon::NativeGetIpOrMacAddress(napi_env env, void *data, int32_t networkAddress) { EDMLOGI("NAPI_NativeGetIpOrMacAddress called"); if (data == nullptr) { @@ -235,13 +246,14 @@ void NetworkManagerAddon::NativeGetIpOrMacAddress(napi_env env, void *data) return; } AdapterAddonData *asyncCallbackInfo = static_cast(data); + asyncCallbackInfo->data.WriteInt32(networkAddress); auto networkManagerProxy = NetworkManagerProxy::GetNetworkManagerProxy(); if (networkManagerProxy == nullptr) { EDMLOGE("can not get GetNetworkManagerProxy"); return; } asyncCallbackInfo->ret = networkManagerProxy->GetIpOrMacAddress(asyncCallbackInfo->data, - asyncCallbackInfo->policyCode, asyncCallbackInfo->stringRet); + EdmInterfaceCode::GET_IP_ADDRESS, asyncCallbackInfo->stringRet); } void NetworkManagerAddon::IsNetworkInterfaceDisabledCommon(AddonMethodSign &addonMethodSign, @@ -1062,19 +1074,19 @@ napi_value NetworkManagerAddon::GetAllNetworkInterfacesSync(napi_env env, napi_c napi_value NetworkManagerAddon::GetIpAddressSync(napi_env env, napi_callback_info info) { EDMLOGI("NAPI_GetIpAddressSync called"); - return GetIpOrMacAddressSync(env, info, EdmInterfaceCode::GET_IP_ADDRESS); + return GetIpOrMacAddressSync(env, info, NetworkAddress::IPADDRESS); } napi_value NetworkManagerAddon::GetMacSync(napi_env env, napi_callback_info info) { EDMLOGI("NAPI_GetMacSync called"); - return GetIpOrMacAddressSync(env, info, EdmInterfaceCode::GET_MAC); + return GetIpOrMacAddressSync(env, info, NetworkAddress::MAC); } -napi_value NetworkManagerAddon::GetIpOrMacAddressSync(napi_env env, napi_callback_info info, int policyCode) +napi_value NetworkManagerAddon::GetIpOrMacAddressSync(napi_env env, napi_callback_info info, int32_t networkAddress) { AddonMethodSign addonMethodSign; - GetIpOrMacAddressCommon(addonMethodSign, EdmConstants::PERMISSION_TAG_VERSION_12, policyCode); + GetIpOrMacAddressCommon(addonMethodSign, EdmConstants::PERMISSION_TAG_VERSION_12); AdapterAddonData adapterAddonData{}; if (JsObjectToData(env, info, addonMethodSign, &adapterAddonData) == nullptr) { return nullptr; @@ -1084,8 +1096,10 @@ napi_value NetworkManagerAddon::GetIpOrMacAddressSync(napi_env env, napi_callbac EDMLOGE("can not get GetNetworkManagerProxy"); return nullptr; } + adapterAddonData.data.WriteInt32(networkAddress); std::string ipOrMacInfo; - int32_t ret = networkManagerProxy->GetIpOrMacAddress(adapterAddonData.data, policyCode, ipOrMacInfo); + int32_t ret = networkManagerProxy->GetIpOrMacAddress( + adapterAddonData.data, EdmInterfaceCode::GET_IP_ADDRESS, ipOrMacInfo); if (FAILED(ret)) { napi_throw(env, CreateError(env, ret)); return nullptr; diff --git a/interfaces/kits/wifi_manager/src/wifi_manager_addon.cpp b/interfaces/kits/wifi_manager/src/wifi_manager_addon.cpp index 52c829b28..88fd44731 100644 --- a/interfaces/kits/wifi_manager/src/wifi_manager_addon.cpp +++ b/interfaces/kits/wifi_manager/src/wifi_manager_addon.cpp @@ -18,6 +18,7 @@ #include "edm_log.h" #include "message_parcel_utils.h" #include "securec.h" +#include "edm_utils.h" #include "napi_edm_adapter.h" using namespace OHOS::EDM; @@ -347,7 +348,9 @@ bool WifiManagerAddon::GetWifiIdFromNAPI(napi_env env, napi_value value, WifiId return false; } wifiId.SetSsid(ssid); + EdmUtils::ClearString(ssid); wifiId.SetBssid(bssid); + EdmUtils::ClearString(bssid); return true; } @@ -533,6 +536,8 @@ bool WifiManagerAddon::JsObjToDeviceConfig(napi_env env, napi_value object, Wifi !JsObjectToInt(env, object, "netId", false, config.networkId) || !JsObjectToInt(env, object, "ipType", false, ipType) || !ProcessIpType(ipType, env, object, config.wifiIpConfig)) { + EdmUtils::ClearString(config.ssid); + EdmUtils::ClearString(config.bssid); return false; } if (ret.size() != 0) { diff --git a/services/edm/include/query_policy/disable_maintenance_mode_query.h b/services/edm/include/query_policy/disable_maintenance_mode_query.h index 3e0a66968..10c5b7c0a 100644 --- a/services/edm/include/query_policy/disable_maintenance_mode_query.h +++ b/services/edm/include/query_policy/disable_maintenance_mode_query.h @@ -15,9 +15,9 @@ #ifndef SERVICES_EDM_INCLUDE_QUERY_POLICY_DISALBE_MAINTENANCE_MODE_QUERY_H #define SERVICES_EDM_INCLUDE_QUERY_POLICY_DISALBE_MAINTENANCE_MODE_QUERY_H - + #include "ipolicy_query.h" - + namespace OHOS { namespace EDM { diff --git a/services/edm/src/enterprise_device_mgr_ability.cpp b/services/edm/src/enterprise_device_mgr_ability.cpp index 612e2ab2e..b86712426 100644 --- a/services/edm/src/enterprise_device_mgr_ability.cpp +++ b/services/edm/src/enterprise_device_mgr_ability.cpp @@ -948,13 +948,13 @@ ErrCode EnterpriseDeviceMgrAbility::CheckReplaceAdmins(const AppExecFwk::Element AAFwk::Want want; want.SetElement(newAdmin); if (!GetBundleMgr()->QueryExtensionAbilityInfos(want, AppExecFwk::ExtensionAbilityType::ENTERPRISE_ADMIN, - AppExecFwk::ExtensionAbilityInfoFlag::GET_EXTENSION_INFO_WITH_PERMISSION, DEFAULT_USER_ID, abilityInfo) || - abilityInfo.empty()) { + AppExecFwk::ExtensionAbilityInfoFlag::GET_EXTENSION_INFO_WITH_PERMISSION, EdmConstants::DEFAULT_USER_ID, + abilityInfo) || abilityInfo.empty()) { EDMLOGW("ReplaceSuperAdmin: QueryExtensionAbilityInfos_newAdmin failed"); return EdmReturnErrCode::COMPONENT_INVALID; } - if (FAILED(VerifyEnableAdminCondition(newAdmin, AdminType::ENT, DEFAULT_USER_ID, false))) { + if (FAILED(VerifyEnableAdminCondition(newAdmin, AdminType::ENT, EdmConstants::DEFAULT_USER_ID, false))) { EDMLOGW("ReplaceSuperAdmin: VerifyEnableAdminCondition failed."); return EdmReturnErrCode::REPLACE_ADMIN_FAILED; } @@ -1006,7 +1006,7 @@ ErrCode EnterpriseDeviceMgrAbility::HandleKeepPolicy(std::string &adminName, std std::string combinedPolicyValue; policyMgr_->GetPolicy("", PolicyName::POLICY_DISALLOWED_UNINSTALL_BUNDLES, combinedPolicyValue); - if (FAILED(policyMgr_->ReplaceAllPolicy(DEFAULT_USER_ID, adminName, newAdminName))) { + if (FAILED(policyMgr_->ReplaceAllPolicy(EdmConstants::DEFAULT_USER_ID, adminName, newAdminName))) { EDMLOGE("ReplaceSuperAdmin update device Policies Failed"); AdminManager::GetInstance()->ReplaceSuperAdminByPackageName(newAdminName, *adminPtr); return EdmReturnErrCode::REPLACE_ADMIN_FAILED; @@ -1073,8 +1073,8 @@ ErrCode EnterpriseDeviceMgrAbility::ReplaceSuperAdmin(const AppExecFwk::ElementN return EdmReturnErrCode::REPLACE_ADMIN_FAILED; } if (FAILED(AdminManager::GetInstance()->SetAdminValue(DEFAULT_USER_ID, edmAdmin))) { - EDMLOGE("EnableAdmin: SetAdminValue failed."); - return EdmReturnErrCode::ENABLE_ADMIN_FAILED; + EDMLOGE("ReplaceSuperAdmin: SetAdminValue failed."); + return EdmReturnErrCode::REPLACE_ADMIN_FAILED; } } system::SetParameter(PARAM_EDM_ENABLE, "true"); @@ -1083,7 +1083,6 @@ ErrCode EnterpriseDeviceMgrAbility::ReplaceSuperAdmin(const AppExecFwk::ElementN DEFAULT_USER_ID, true); EDMLOGI("EnableAdmin: SetAdminEnabled success %{public}s", newAdmin.GetBundleName().c_str()); - EDMLOGD("ReportEdmEventManagerAdmin ReplaceSuperAdmin"); HiSysEventAdapter::ReportEdmEventManagerAdmin(newAdmin.GetBundleName().c_str(), static_cast(AdminAction::REPLACE), static_cast(AdminType::ENT), oldAdmin.GetBundleName().c_str()); @@ -1306,7 +1305,7 @@ ErrCode EnterpriseDeviceMgrAbility::DisableSuperAdmin(const std::string &bundleN { EDMLOGI("EnterpriseDeviceMgrAbility::DisableSuperAdmin bundle name = %{public}s", bundleName.c_str()); std::unique_lock autoLock(adminLock_); - return DoDisableAdmin(bundleName, DEFAULT_USER_ID, AdminType::ENT); + return DoDisableAdmin(bundleName, EdmConstants::DEFAULT_USER_ID, AdminType::ENT); } bool EnterpriseDeviceMgrAbility::CheckDisableAdmin(const std::string &bundleName, AdminType adminType, bool isDebug) @@ -1951,9 +1950,7 @@ ErrCode EnterpriseDeviceMgrAbility::SetDelegatedPolicies(const AppExecFwk::Eleme GetCurrentUserId()); ErrCode ret = GetPermissionChecker()->CheckCallerPermission(adminItem, EdmPermission::PERMISSION_ENTERPRISE_MANAGE_DELEGATED_POLICY, true); - if (FAILED(ret)) { - return ret; - } + if (FAILED(ret)) return ret; if (parentAdminName == bundleName) { EDMLOGE("SetDelegatedPolicies does not delegated policies to self."); return EdmReturnErrCode::PARAM_ERROR; @@ -1968,9 +1965,7 @@ ErrCode EnterpriseDeviceMgrAbility::SetDelegatedPolicies(const AppExecFwk::Eleme return ret; } ret = CheckDelegatedPolicies(adminItem, policies); - if (FAILED(ret)) { - return ret; - } + if (FAILED(ret)) return ret; if (!GetBundleMgr()->IsBundleInstalled(bundleName, GetCurrentUserId())) { EDMLOGE("SetDelegatedPolicies the delegated application does not installed."); return EdmReturnErrCode::AUTHORIZE_PERMISSION_FAILED; diff --git a/services/edm/src/query_policy/allowed_bluetooth_devices_query.cpp b/services/edm/src/query_policy/allowed_bluetooth_devices_query.cpp index de5427de6..8ae13c542 100644 --- a/services/edm/src/query_policy/allowed_bluetooth_devices_query.cpp +++ b/services/edm/src/query_policy/allowed_bluetooth_devices_query.cpp @@ -33,7 +33,6 @@ std::string AllowedBluetoothDevicesQuery::GetPermission(IPlugin::PermissionType, ErrCode AllowedBluetoothDevicesQuery::QueryPolicy(std::string &policyData, MessageParcel &data, MessageParcel &reply, int32_t userId) { - EDMLOGI("AllowedBluetoothDevicesQuery OnGetPolicy policyData : %{public}s", policyData.c_str()); return GetArrayStringPolicy(policyData, reply); } } // namespace EDM diff --git a/services/edm/src/query_policy/disallowed_mobile_data_query.cpp b/services/edm/src/query_policy/disallowed_mobile_data_query.cpp index d88c0ec2b..e7ed2c383 100644 --- a/services/edm/src/query_policy/disallowed_mobile_data_query.cpp +++ b/services/edm/src/query_policy/disallowed_mobile_data_query.cpp @@ -34,6 +34,8 @@ std::string DisallowedMobileDataQuery::GetPermission(IPlugin::PermissionType per ErrCode DisallowedMobileDataQuery::QueryPolicy(std::string &policyData, MessageParcel &data, MessageParcel &reply, int32_t userId) { + EDMLOGI("DisallowedMobileDataQuery QueryPolicy policyData : %{public}s", policyData.c_str()); + policyData = (policyData == "disallow") ? "true" : "false"; return GetBoolPolicy(policyData, reply); } } // namespace EDM diff --git a/services/edm/src/user_policy_manager.cpp b/services/edm/src/user_policy_manager.cpp index 5d20b4cc3..8d680a12a 100644 --- a/services/edm/src/user_policy_manager.cpp +++ b/services/edm/src/user_policy_manager.cpp @@ -303,7 +303,7 @@ ErrCode UserPolicyManager::SetPolicy(const std::string &adminName, const std::st } if (FAILED(err)) { EDMLOGW("Set or delete combined policy failed:%{public}d, merged policy:%{public}s\n", - err, mergedPolicy.c_str()); + err, policyName.c_str()); } if (!adminName.empty()) { @@ -315,7 +315,7 @@ ErrCode UserPolicyManager::SetPolicy(const std::string &adminName, const std::st } if (FAILED(err)) { EDMLOGW("Set or delete admin policy failed:%{public}d, admin policy:%{public}s\n", - err, adminPolicy.c_str()); + err, adminName.c_str()); } return err; } diff --git a/services/edm_plugin/BUILD.gn b/services/edm_plugin/BUILD.gn index e0d30a1b5..9ff96a305 100644 --- a/services/edm_plugin/BUILD.gn +++ b/services/edm_plugin/BUILD.gn @@ -348,8 +348,7 @@ ohos_shared_library("communication_plugin") { ] sources += [ "./src/get_all_network_interfaces_plugin.cpp", - "./src/get_ip_address_plugin.cpp", - "./src/get_mac_plugin.cpp", + "./src/get_ip_or_mac_address_plugin.cpp", "./src/disallow_vpn_plugin.cpp" ] } diff --git a/services/edm_plugin/include/get_ip_address_plugin.h b/services/edm_plugin/include/get_ip_or_mac_address_plugin.h similarity index 65% rename from services/edm_plugin/include/get_ip_address_plugin.h rename to services/edm_plugin/include/get_ip_or_mac_address_plugin.h index fee8f2d52..f33c6fe34 100644 --- a/services/edm_plugin/include/get_ip_address_plugin.h +++ b/services/edm_plugin/include/get_ip_or_mac_address_plugin.h @@ -13,20 +13,20 @@ * limitations under the License. */ -#ifndef SERVICES_EDM_PLUGIN_INCLUDE_GET_IP_ADDRESS_PLUGIN_H -#define SERVICES_EDM_PLUGIN_INCLUDE_GET_IP_ADDRESS_PLUGIN_H +#ifndef SERVICES_EDM_PLUGIN_INCLUDE_GET_IP_OR_MAC_ADDRESS_PLUGIN_H +#define SERVICES_EDM_PLUGIN_INCLUDE_GET_IP_OR_MAC_ADDRESS_PLUGIN_H #include "plugin_singleton.h" namespace OHOS { namespace EDM { -class GetIpAddressPlugin : public PluginSingleton { +class GetIpOrMacAddressPlugin : public PluginSingleton { public: - void InitPlugin(std::shared_ptr> ptr) override; + void InitPlugin(std::shared_ptr> ptr) override; ErrCode OnGetPolicy(std::string &policyData, MessageParcel &data, MessageParcel &reply, int32_t userId) override; }; } // namespace EDM } // namespace OHOS -#endif // SERVICES_EDM_PLUGIN_INCLUDE_GET_IP_ADDRESS_PLUGIN_H +#endif // SERVICES_EDM_PLUGIN_INCLUDE_GET_IP_OR_MAC_ADDRESS_PLUGIN_H diff --git a/services/edm_plugin/src/allowed_usb_devices_plugin.cpp b/services/edm_plugin/src/allowed_usb_devices_plugin.cpp index 7668a9ff4..71b8c8914 100644 --- a/services/edm_plugin/src/allowed_usb_devices_plugin.cpp +++ b/services/edm_plugin/src/allowed_usb_devices_plugin.cpp @@ -62,12 +62,8 @@ ErrCode AllowUsbDevicesPlugin::OnSetPolicy(std::vector &data, return EdmReturnErrCode::CONFIGURATION_CONFLICT_FAILED; } - std::vector needAddData = - ArrayUsbDeviceIdSerializer::GetInstance()->SetDifferencePolicyData(currentData, data); - std::vector needAddMergeData = - ArrayUsbDeviceIdSerializer::GetInstance()->SetDifferencePolicyData(mergeData, needAddData); std::vector afterHandle = - ArrayUsbDeviceIdSerializer::GetInstance()->SetUnionPolicyData(currentData, needAddData); + ArrayUsbDeviceIdSerializer::GetInstance()->SetUnionPolicyData(currentData, data); std::vector afterMerge = ArrayUsbDeviceIdSerializer::GetInstance()->SetUnionPolicyData(mergeData, afterHandle); @@ -75,7 +71,7 @@ ErrCode AllowUsbDevicesPlugin::OnSetPolicy(std::vector &data, EDMLOGE("AllowUsbDevicesPlugin OnSetPolicy union data size=[%{public}zu] is too large", mergeData.size()); return EdmReturnErrCode::PARAM_ERROR; } - ErrCode errCode = UsbPolicyUtils::AddAllowedUsbDevices(needAddMergeData); + ErrCode errCode = UsbPolicyUtils::AddAllowedUsbDevices(afterMerge); if (errCode != ERR_OK) { return errCode; } diff --git a/services/edm_plugin/src/disallow_mobile_data_plugin.cpp b/services/edm_plugin/src/disallow_mobile_data_plugin.cpp index 3694ddc53..31736bbd4 100644 --- a/services/edm_plugin/src/disallow_mobile_data_plugin.cpp +++ b/services/edm_plugin/src/disallow_mobile_data_plugin.cpp @@ -66,8 +66,8 @@ ErrCode DisallowMobileDataPlugin::OnHandlePolicy(std::uint32_t funcCode, Message return EdmReturnErrCode::SYSTEM_ABNORMALLY; } policyData.isChanged = true; - policyData.mergePolicyData = "true"; - policyData.policyData = "true"; + policyData.mergePolicyData = "disallow"; + policyData.policyData = "disallow"; return ERR_OK; } if (!system::SetParameter(PARAM_MOBILE_DATA_POLICY, MOBILE_DATA_NONE)) { @@ -75,12 +75,19 @@ ErrCode DisallowMobileDataPlugin::OnHandlePolicy(std::uint32_t funcCode, Message return EdmReturnErrCode::SYSTEM_ABNORMALLY; } policyData.isChanged = true; - policyData.mergePolicyData = "false"; - policyData.policyData = "false"; + policyData.mergePolicyData = "none"; + policyData.policyData = "none"; return ERR_OK; } if (flag == EdmConstants::MobileData::FORCE_FLAG) { - return OnHandleForceOpen(data); + int32_t ret = OnHandleForceOpen(data); + if (ret != ERR_OK) { + return ret; + } + policyData.isChanged = true; + policyData.mergePolicyData = "force_open"; + policyData.policyData = "force_open"; + return ERR_OK; } return EdmReturnErrCode::SYSTEM_ABNORMALLY; } @@ -113,7 +120,7 @@ ErrCode DisallowMobileDataPlugin::OnHandleForceOpen(MessageParcel &data) ErrCode DisallowMobileDataPlugin::OnAdminRemove(const std::string &adminName, const std::string &policyData, const std::string &mergeData, int32_t userId) { - EDMLOGI("TurnOnOffMobileDataPlugin OnAdminRemove adminName : %{public}s, policyData : %{public}s", + EDMLOGI("DisallowMobileDataPlugin OnAdminRemove adminName : %{public}s, policyData : %{public}s", adminName.c_str(), policyData.c_str()); if (!system::SetParameter(PARAM_MOBILE_DATA_POLICY, MOBILE_DATA_NONE)) { EDMLOGE("DisallowMobileDataPlugin:OnSetPolicy SetParameter fail"); diff --git a/services/edm_plugin/src/get_ip_address_plugin.cpp b/services/edm_plugin/src/get_ip_or_mac_address_plugin.cpp similarity index 72% rename from services/edm_plugin/src/get_ip_address_plugin.cpp rename to services/edm_plugin/src/get_ip_or_mac_address_plugin.cpp index 61cc0e0cb..16522ae90 100644 --- a/services/edm_plugin/src/get_ip_address_plugin.cpp +++ b/services/edm_plugin/src/get_ip_or_mac_address_plugin.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "get_ip_address_plugin.h" +#include "get_ip_or_mac_address_plugin.h" #include "edm_constants.h" #include "edm_ipc_interface_code.h" @@ -21,14 +21,15 @@ #include "interface_type.h" #include "string_serializer.h" #include "iplugin_manager.h" +#include "network_address.h" namespace OHOS { namespace EDM { -const bool REGISTER_RESULT = IPluginManager::GetInstance()->AddPlugin(GetIpAddressPlugin::GetPlugin()); +const bool REGISTER_RESULT = IPluginManager::GetInstance()->AddPlugin(GetIpOrMacAddressPlugin::GetPlugin()); -void GetIpAddressPlugin::InitPlugin(std::shared_ptr> ptr) +void GetIpOrMacAddressPlugin::InitPlugin(std::shared_ptr> ptr) { - EDMLOGI("GetIpAddressPlugin InitPlugin..."); + EDMLOGI("GetIpOrMacAddressPlugin InitPlugin..."); std::map> tagPermissions; std::map typePermissionsForTag11; std::map typePermissionsForTag12; @@ -40,20 +41,25 @@ void GetIpAddressPlugin::InitPlugin(std::shared_ptrInitAttribute(EdmInterfaceCode::GET_IP_ADDRESS, PolicyName::POLICY_GET_IP_ADDRESS, config, false); + ptr->InitAttribute(EdmInterfaceCode::GET_IP_ADDRESS, PolicyName::POLICY_GET_IP_OR_MAC_ADDRESS, config, false); ptr->SetSerializer(StringSerializer::GetInstance()); } -ErrCode GetIpAddressPlugin::OnGetPolicy(std::string &policyData, MessageParcel &data, MessageParcel &reply, +ErrCode GetIpOrMacAddressPlugin::OnGetPolicy(std::string &policyData, MessageParcel &data, MessageParcel &reply, int32_t userId) { - EDMLOGI("GetIpAddressPlugin OnGetPolicy."); + EDMLOGI("GetIpOrMacAddressPlugin OnGetPolicy."); nmd::InterfaceConfigurationParcel config; std::string networkInterface; data.ReadString(networkInterface); DelayedSingleton::GetInstance()->GetInterfaceConfig(networkInterface, config); reply.WriteInt32(ERR_OK); - reply.WriteString(config.ipv4Addr); + int32_t networkAddress = data.ReadInt32(); + if (networkAddress == NetworkAddress::IPADDRESS) { + reply.WriteString(config.ipv4Addr); + } else if (networkAddress == NetworkAddress::MAC) { + reply.WriteString(config.hwAddr); + } return ERR_OK; } } // namespace EDM diff --git a/services/edm_plugin/src/get_mac_plugin.cpp b/services/edm_plugin/src/get_mac_plugin.cpp deleted file mode 100644 index db752c20c..000000000 --- a/services/edm_plugin/src/get_mac_plugin.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 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 "get_mac_plugin.h" - -#include "edm_constants.h" -#include "edm_ipc_interface_code.h" -#include "ethernet_client.h" -#include "interface_type.h" -#include "string_serializer.h" -#include "iplugin_manager.h" - -namespace OHOS { -namespace EDM { -const bool REGISTER_RESULT = IPluginManager::GetInstance()->AddPlugin(GetMacPlugin::GetPlugin()); - -void GetMacPlugin::InitPlugin(std::shared_ptr> ptr) -{ - EDMLOGI("GetMacPlugin InitPlugin..."); - std::map> tagPermissions; - std::map typePermissionsForTag11; - std::map typePermissionsForTag12; - typePermissionsForTag11.emplace(IPlugin::PermissionType::SUPER_DEVICE_ADMIN, - EdmPermission::PERMISSION_ENTERPRISE_GET_NETWORK_INFO); - typePermissionsForTag12.emplace(IPlugin::PermissionType::SUPER_DEVICE_ADMIN, - EdmPermission::PERMISSION_ENTERPRISE_MANAGE_NETWORK); - tagPermissions.emplace(EdmConstants::PERMISSION_TAG_VERSION_11, typePermissionsForTag11); - tagPermissions.emplace(EdmConstants::PERMISSION_TAG_VERSION_12, typePermissionsForTag12); - - IPlugin::PolicyPermissionConfig config = IPlugin::PolicyPermissionConfig(tagPermissions, IPlugin::ApiType::PUBLIC); - ptr->InitAttribute(EdmInterfaceCode::GET_MAC, PolicyName::POLICY_GET_MAC, config, false); - ptr->SetSerializer(StringSerializer::GetInstance()); -} - -ErrCode GetMacPlugin::OnGetPolicy(std::string &policyData, MessageParcel &data, MessageParcel &reply, int32_t userId) -{ - EDMLOGI("GetMacPlugin OnGetPolicy."); - nmd::InterfaceConfigurationParcel config; - std::string networkInterface; - data.ReadString(networkInterface); - DelayedSingleton::GetInstance()->GetInterfaceConfig(networkInterface, config); - reply.WriteInt32(ERR_OK); - reply.WriteString(config.hwAddr); - return ERR_OK; -} -} // namespace EDM -} // namespace OHOS diff --git a/services/edm_plugin/src/install_plugin.cpp b/services/edm_plugin/src/install_plugin.cpp index ffb906415..77552b786 100644 --- a/services/edm_plugin/src/install_plugin.cpp +++ b/services/edm_plugin/src/install_plugin.cpp @@ -26,7 +26,6 @@ #include "directory_ex.h" #include "edm_ipc_interface_code.h" #include "edm_sys_manager.h" -#include "install_param_serializer.h" #include "installer_callback.h" #include "iplugin_manager.h" diff --git a/services/edm_plugin/src/utils/apn_utils.cpp b/services/edm_plugin/src/utils/apn_utils.cpp index 6401bf5b0..9f673a172 100644 --- a/services/edm_plugin/src/utils/apn_utils.cpp +++ b/services/edm_plugin/src/utils/apn_utils.cpp @@ -78,9 +78,11 @@ int32_t ApnUtils::GetOpkey(const std::string &mccmnc, std::string &opkey) int32_t columnIndex = -1; if (queryResult->GetColumnIndex("operator_key", columnIndex) != DataShare::E_OK || queryResult->GetString(columnIndex, opkey) != DataShare::E_OK) { + EDMLOGE("GetOpkey GetColumnIndex or GetString error"); + queryResult->Close(); return -1; } - EDMLOGI("ApnUtils::GetOpkey opkey=%{public}s", opkey.c_str()); + queryResult->Close(); return 0; } @@ -97,6 +99,10 @@ int32_t ApnUtils::ApnInsert(const std::map &apnInfo, for (const auto & [key, value] : apnInfo) { values.Put(key, value); } + if (apnInfo.find(PdpProfileData::MCC) == apnInfo.end() || apnInfo.find(PdpProfileData::MNC) == apnInfo.end()) { + EDMLOGE("Mandatory keys MCC or MNC not found in apnInfo"); + return EdmReturnErrCode::PARAM_ERROR; + } if (apnUtilsPassword.password != nullptr) { values.Put("auth_pwd", std::string(apnUtilsPassword.password, apnUtilsPassword.passwordSize)); } @@ -148,9 +154,15 @@ int32_t ApnUtils::ApnUpdate(const std::map &apnInfo, c if (apnInfo.find(PdpProfileData::MCC) != apnInfo.end() && apnInfo.find(PdpProfileData::MNC) != apnInfo.end()) { mccmnc = apnInfo.at(PdpProfileData::MCC) + apnInfo.at(PdpProfileData::MNC); } else if (apnInfo.find(PdpProfileData::MCC) != apnInfo.end()) { - mccmnc = apnInfo.at(PdpProfileData::MCC) + ApnQuery(apnId)[PdpProfileData::MNC]; + auto queryResult = ApnQuery(apnId); + if (queryResult.find(PdpProfileData::MNC) != queryResult.end()) { + mccmnc = apnInfo.at(PdpProfileData::MCC) + queryResult.at(PdpProfileData::MNC); + } } else if (apnInfo.find(PdpProfileData::MNC) != apnInfo.end()) { - mccmnc = ApnQuery(apnId)[PdpProfileData::MCC] + apnInfo.at(PdpProfileData::MNC); + auto queryResult = ApnQuery(apnId); + if (queryResult.find(PdpProfileData::MCC) != queryResult.end()) { + mccmnc = queryResult.at(PdpProfileData::MCC) + apnInfo.at(PdpProfileData::MNC); + } } if (apnInfo.find(PdpProfileData::MCC) != apnInfo.end() || apnInfo.find(PdpProfileData::MNC) != apnInfo.end()) { @@ -299,8 +311,13 @@ int32_t ApnUtils::MatchValidSimId(const std::string &opkey, int32_t slotId) int32_t ApnUtils::GetValidSimId(const std::string &apnId) { + std::map mapData = ApnQuery(apnId); + std::string mccmnc; + if (mapData.find(PdpProfileData::MCCMNC) != mapData.end()) { + mccmnc = mapData[PdpProfileData::MCCMNC]; + } std::string opkey; - if (GetOpkey(ApnQuery(apnId)[PdpProfileData::MCCMNC], opkey) != ERR_OK || opkey.empty()) { + if (GetOpkey(mccmnc, opkey) != ERR_OK || opkey.empty()) { return -1; } diff --git a/services/edm_plugin/src/utils/bluetooth_config_utils.cpp b/services/edm_plugin/src/utils/bluetooth_config_utils.cpp index 7f9a0ae43..e1ba35bdc 100644 --- a/services/edm_plugin/src/utils/bluetooth_config_utils.cpp +++ b/services/edm_plugin/src/utils/bluetooth_config_utils.cpp @@ -38,6 +38,7 @@ BluetoothConfigUtils::BluetoothConfigUtils() if (std::find(files.begin(), files.end(), BLUETOOTH_DIR) == files.end()) { CreateBluetoothConfigDir(CONFIG_SYSTEM_ALL_DIR + SEPARATOR + BLUETOOTH_DIR); } + LoadConfig(); } BluetoothConfigUtils::~BluetoothConfigUtils() diff --git a/services/edm_plugin/src/utils/nearlink_config_utils.cpp b/services/edm_plugin/src/utils/nearlink_config_utils.cpp index a5f957f25..6a3d5241b 100644 --- a/services/edm_plugin/src/utils/nearlink_config_utils.cpp +++ b/services/edm_plugin/src/utils/nearlink_config_utils.cpp @@ -97,7 +97,12 @@ bool NearlinkConfigUtils::AddProtocol( if (!userItem) { // 新增用户条目 - CJSON_CREATE_ARRAY_AND_CHECK(userItem, false); + userItem = cJSON_CreateArray(); + if (userItem == nullptr) { + EDMLOGE("cJSON_CreateArray Error"); + cJSON_Delete(protocols); + return false; + } CJSON_ADD_ITEM_TO_ARRAY_AND_CHECK_AND_CLEAR(protocols, userItem, false); if (!cJSON_AddItemToObject(denyList, userId.c_str(), userItem)) { EDMLOGE("cJSON_AddItemToObject Error"); @@ -223,7 +228,7 @@ bool NearlinkConfigUtils::LoadConfig() if (inFile.good()) { EDMLOGI("NearlinkConfigUtils::LoadConfig inFile.good"); inFile.seekg(0, std::ios::end); - size_t size = inFile.tellg(); + size_t size = static_cast(inFile.tellg()); if (size == 0) { inFile.close(); CJSON_CREATE_OBJECT_AND_CHECK(root_, false); diff --git a/services/edm_plugin/src/utils/wifi_policy_utils.cpp b/services/edm_plugin/src/utils/wifi_policy_utils.cpp index cb215e7c8..34f67ecbb 100644 --- a/services/edm_plugin/src/utils/wifi_policy_utils.cpp +++ b/services/edm_plugin/src/utils/wifi_policy_utils.cpp @@ -18,6 +18,7 @@ #include "array_wifi_id_serializer.h" #include "edm_constants.h" #include "edm_log.h" +#include "edm_utils.h" #include "ipolicy_manager.h" #include "wifi_device.h" @@ -124,6 +125,7 @@ bool WifiPolicyUtils::CheckWifiId(std::vector &data, bool isAllowed) EDMLOGE("CheckWifiList ssid is empty or too large!"); return false; } + EdmUtils::ClearString(ssid); std::string bssid = wifiId.GetBssid(); if (isAllowed && bssid.empty()) { EDMLOGE("CheckWifiList bssid parse error!"); @@ -133,6 +135,7 @@ bool WifiPolicyUtils::CheckWifiId(std::vector &data, bool isAllowed) EDMLOGE("CheckWifiList bssid parse error!"); return false; } + EdmUtils::ClearString(bssid); } return true; } diff --git a/test/fuzztest/common/src/common_fuzzer.cpp b/test/fuzztest/common/src/common_fuzzer.cpp index 3d567d74a..9bd3d5477 100644 --- a/test/fuzztest/common/src/common_fuzzer.cpp +++ b/test/fuzztest/common/src/common_fuzzer.cpp @@ -49,8 +49,7 @@ #include "get_all_network_interfaces_plugin.h" #include "get_bluetooth_info_plugin.h" #include "get_device_info_plugin.h" -#include "get_ip_address_plugin.h" -#include "get_mac_plugin.h" +#include "get_ip_or_mac_address_plugin.h" #include "global_proxy_plugin.h" #include "ienterprise_device_mgr.h" #ifdef FEATURE_PC_ONLY @@ -134,14 +133,15 @@ const bool REGISTER_GET_ALL_NETWORK_INTERFACES_PLUGIN = const bool REGISTER_GET_BLUETOOTH_INFO_PLUGIN = PluginManager::GetInstance()->AddPlugin(GetBluetoothInfoPlugin::GetPlugin()); const bool REGISTER_GET_DEVICE_INFO_PLUGIN = PluginManager::GetInstance()->AddPlugin(GetDeviceInfoPlugin::GetPlugin()); -const bool REGISTER_GET_IP_ADDRESS_PLUGIN = PluginManager::GetInstance()->AddPlugin(GetIpAddressPlugin::GetPlugin()); -const bool REGISTER_GET_MAC_PLUGIN = PluginManager::GetInstance()->AddPlugin(GetMacPlugin::GetPlugin()); +const bool REGISTER_GET_IP_OR_MAC_ADDRESS_PLUGIN = + PluginManager::GetInstance()->AddPlugin(GetIpOrMacAddressPlugin::GetPlugin()); const bool REGISTER_GLOBAL_PROXY_PLUGIN = PluginManager::GetInstance()->AddPlugin(GlobalProxyPlugin::GetPlugin()); const bool REGISTER_INSTALL_PLUGIN = PluginManager::GetInstance()->AddPlugin(InstallPlugin::GetPlugin()); const bool REGISTER_IPTABLES_RULE_PLUGIN = PluginManager::GetInstance()->AddPlugin(std::make_shared()); const bool REGISTER_IS_WIFI_ACTIVE_PLUGIN = PluginManager::GetInstance()->AddPlugin(IsWifiActivePlugin::GetPlugin()); -const bool REGISTER_LOCATION_POLICY_PLUGIN = PluginManager::GetInstance()->AddPlugin(LocationPolicyPlugin::GetPlugin()); +const bool REGISTER_LOCATION_POLICY_PLUGIN = + PluginManager::GetInstance()->AddPlugin(LocationPolicyPlugin::GetPlugin()); const bool REGISTER_LOCK_SCREEN_PLUGIN = PluginManager::GetInstance()->AddPlugin(LockScreenPlugin::GetPlugin()); const bool REGISTER_MANAGE_AUTO_START_APPS_PLUGIN = PluginManager::GetInstance()->AddPlugin(std::make_shared()); diff --git a/test/fuzztest/enterprisedevicemgrstubmock_fuzzer/BUILD.gn b/test/fuzztest/enterprisedevicemgrstubmock_fuzzer/BUILD.gn index 8aa6d9cd0..0f5ac3606 100644 --- a/test/fuzztest/enterprisedevicemgrstubmock_fuzzer/BUILD.gn +++ b/test/fuzztest/enterprisedevicemgrstubmock_fuzzer/BUILD.gn @@ -279,8 +279,7 @@ ohos_static_library("edmservice_fuzz_static") { "../../../services/edm_plugin/src/domain_filter_rule_plugin.cpp", "../../../services/edm_plugin/src/firewall_rule_plugin.cpp", "../../../services/edm_plugin/src/get_all_network_interfaces_plugin.cpp", - "../../../services/edm_plugin/src/get_ip_address_plugin.cpp", - "../../../services/edm_plugin/src/get_mac_plugin.cpp", + "../../../services/edm_plugin/src/get_ip_or_mac_address_plugin.cpp", "../../../services/edm_plugin/src/global_proxy_plugin.cpp", "../../../services/edm_plugin/src/iptables_rule_plugin.cpp", "../../../services/edm_plugin/src/network/executer/domain_executer.cpp", diff --git a/test/unittest/services/edm/BUILD.gn b/test/unittest/services/edm/BUILD.gn index 5dbd79a26..9ed26f61a 100644 --- a/test/unittest/services/edm/BUILD.gn +++ b/test/unittest/services/edm/BUILD.gn @@ -92,6 +92,7 @@ ohos_static_library("edmservice_static") { "../../../../services/edm_plugin/src/utils/usb_policy_utils.cpp", "../../../../services/edm/src/query_policy/disallowed_sms_query.cpp", "../../../../services/edm/src/query_policy/disallowed_mms_query.cpp", + "../../../../services/edm_plugin/src/set_browser_policies_plugin.cpp", ] public_configs = [ diff --git a/test/unittest/services/edm/src/enterprise_device_mgr_ability_test.cpp b/test/unittest/services/edm/src/enterprise_device_mgr_ability_test.cpp index d60394c36..f64f8c7f9 100644 --- a/test/unittest/services/edm/src/enterprise_device_mgr_ability_test.cpp +++ b/test/unittest/services/edm/src/enterprise_device_mgr_ability_test.cpp @@ -34,6 +34,7 @@ #include "plugin_manager_test.h" #include "utils.h" #include "edm_log.h" +#include "set_browser_policies_plugin.h" using namespace testing; using namespace testing::ext; @@ -3265,14 +3266,11 @@ HWTEST_F(EnterpriseDeviceMgrAbilityTest, TestGetDevicePolicyInnerWithoutAdminSuc { EXPECT_CALL(*osAccountMgrMock_, IsOsAccountExists).WillOnce(DoAll(SetArgReferee<1>(true), Return(ERR_OK))); - uint32_t code = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, WITHOUT_ADMIN_SUCCESS_POLICY_CODE); - MessageParcel data; - MessageParcel reply; + uint32_t code = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::GET, WITHOUT_ADMIN_SUCCESS_POLICY_CODE); + MessageParcel data, reply; data.WriteInt32(1); - plugin_->permissionConfig_.typePermissions[IPlugin::PermissionType::NORMAL_DEVICE_ADMIN] = - EDM_MANAGE_DATETIME_PERMISSION; - PluginManager::GetInstance()->NotifyUnloadAllPlugin(); - PluginManager::GetInstance()->AddPlugin(plugin_); + auto browserPlugin = std::make_shared(); + PluginManager::GetInstance()->pluginsCode_[WITHOUT_ADMIN_SUCCESS_POLICY_CODE] = browserPlugin; edmMgr_->GetDevicePolicyInner(code, data, reply, DEFAULT_USER_ID); ASSERT_TRUE(reply.ReadInt32() == ERR_OK); } diff --git a/test/unittest/services/edm_plugin/BUILD.gn b/test/unittest/services/edm_plugin/BUILD.gn index eadb6044c..1f5c67346 100644 --- a/test/unittest/services/edm_plugin/BUILD.gn +++ b/test/unittest/services/edm_plugin/BUILD.gn @@ -555,8 +555,7 @@ ohos_static_library("edm_all_plugin_static") { "../../../../services/edm_plugin/src/domain_filter_rule_plugin.cpp", "../../../../services/edm_plugin/src/firewall_rule_plugin.cpp", "../../../../services/edm_plugin/src/get_all_network_interfaces_plugin.cpp", - "../../../../services/edm_plugin/src/get_ip_address_plugin.cpp", - "../../../../services/edm_plugin/src/get_mac_plugin.cpp", + "../../../../services/edm_plugin/src/get_ip_or_mac_address_plugin.cpp", "../../../../services/edm_plugin/src/global_proxy_plugin.cpp", "../../../../services/edm_plugin/src/iptables_rule_plugin.cpp", "../../../../services/edm_plugin/src/network/executer/domain_executer.cpp", @@ -682,6 +681,7 @@ ohos_static_library("edm_all_plugin_static") { "../../../../services/edm_plugin/src/disallowed_nearlink_protocols_plugin.cpp", "../../../../services/edm_plugin/src/utils/nearlink_config_utils.cpp", "../../../../services/edm_plugin/src/utils/nearlink_protocol_utils.cpp", + "../../../../services/edm_plugin/src/disallowed_usb_storage_device_write_plugin.cpp", ] } diff --git a/test/unittest/services/edm_plugin/src/network_manager_plugin_test.cpp b/test/unittest/services/edm_plugin/src/network_manager_plugin_test.cpp index 7f9523283..1a2497cc6 100644 --- a/test/unittest/services/edm_plugin/src/network_manager_plugin_test.cpp +++ b/test/unittest/services/edm_plugin/src/network_manager_plugin_test.cpp @@ -18,12 +18,12 @@ #include "disabled_network_interface_plugin.h" #include "edm_ipc_interface_code.h" #include "get_all_network_interfaces_plugin.h" -#include "get_ip_address_plugin.h" -#include "get_mac_plugin.h" +#include "get_ip_or_mac_address_plugin.h" #include "iplugin_manager.h" #include "map_string_serializer.h" #include "plugin_singleton.h" #include "utils.h" +#include "network_address.h" using namespace testing::ext; using namespace testing; @@ -75,10 +75,11 @@ HWTEST_F(NetworkManagerPluginTest, TestGetAllNetworkInterfaces, TestSize.Level1) */ HWTEST_F(NetworkManagerPluginTest, TestGetIpAddress, TestSize.Level1) { - std::shared_ptr plugin = GetIpAddressPlugin::GetPlugin(); + std::shared_ptr plugin = GetIpOrMacAddressPlugin::GetPlugin(); std::string policyData{"TestGetIpAddress"}; MessageParcel data; MessageParcel reply; + data.WriteInt32(NetworkAddress::IPADDRESS); ErrCode ret = plugin->OnGetPolicy(policyData, data, reply, DEFAULT_USER_ID); ASSERT_TRUE(ret == ERR_OK); } @@ -90,10 +91,11 @@ HWTEST_F(NetworkManagerPluginTest, TestGetIpAddress, TestSize.Level1) */ HWTEST_F(NetworkManagerPluginTest, TestGetMac, TestSize.Level1) { - std::shared_ptr plugin = GetMacPlugin::GetPlugin(); + std::shared_ptr plugin = GetIpOrMacAddressPlugin::GetPlugin(); std::string policyData{"TestGetMac"}; MessageParcel data; MessageParcel reply; + data.WriteInt32(NetworkAddress::MAC); ErrCode ret = plugin->OnGetPolicy(policyData, data, reply, DEFAULT_USER_ID); ASSERT_TRUE(ret == ERR_OK); } -- Gitee