find_program(LCOV NAMES lcov)
message(STATUS "LCOV: " ${LCOV})
string(TIMESTAMP TIME "%Y-%m-%d_%H:%M:%S")
-SET(COV_FOLDER "coverage/${TIME}")
+SET(COV_FOLDER "/tmp/coverage/${TIME}")
if(${LCOV} STREQUAL "LCOV-NOTFOUND")
message(STATUS "LCOV not found, using GCOVR")
add_custom_target(coverage
* @brief getKeepAliveTimeout returns KeepAlive timeout period
* @return KeepAlive timeout period
*/
- const std::chrono::seconds& getKeepAliveTimeout() const
+ const std::chrono::milliseconds& getKeepAliveTimeout() const
{
return keepAliveTimeout;
}
* @brief setKeepAliveTimeout sets KeepAlive timeout period
* @param keepalive KeepAlive timeout period
*/
- void setKeepAliveTimeout(const std::chrono::seconds& keepalive)
+ void setKeepAliveTimeout(const std::chrono::milliseconds& keepalive)
{
keepAliveTimeout = keepalive;
}
std::string serverAddress;
std::string deviceId;
std::string serial;
- std::chrono::seconds keepAliveTimeout;
+ std::chrono::milliseconds keepAliveTimeout;
std::string saveFileName;
bool loaded;
serverAddress = properties.get<std::string>(PROPKEY_SERVER_ADDR, std::string{});
deviceId = properties.get<std::string>(PROPKEY_DUID, std::string{});
serial = properties.get<std::string>(PROPKEY_SERIAL, std::string{});
- keepAliveTimeout = std::chrono::seconds(properties.get<int>(PROPKEY_KEEPALIVE, DEFAULT_KEEPALIVE_SECONDS));
+ keepAliveTimeout = std::chrono::milliseconds(properties.get<int>(PROPKEY_KEEPALIVE, DEFAULT_KEEPALIVE_SECONDS));
loaded = true;
} catch (std::exception& e) {
LOG_E(TAG, "Fail to load configuration from \"%s\". Error: %s", fileName.c_str(), e.what());
[Server]
URL=http://106.125.46.74:11000/api/device-service/
-keepalive=5
+keepalive=5000
[Device]
type=tv
model=1
/**
* Samsung Ukraine R&D Center (SRK under a contract between)
* LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
- * Copyright (C) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
*/
/**
- * @file iot_common_enforce.cpp
+ * @file common_enforce.cpp
* @brief Implementation of common policy
* @date Created Jul 05, 2016
* @author Mail to: <A HREF="mailto:a.volkov@samsung.com">Aleksey Volkov, a.volkov@samsung.com</A>
*/
-#include "iot_common_enforce.h"
-#include "logging.h"
-#include "dpm_api_mapper.h"
#include <thread>
#include <chrono>
+#include "common_enforce.h"
+#include "logging.h"
+#include "samonitor_tag.h"
+#include "dpm_api_mapper.h"
-#define TAG "nmdaemon"
-namespace iot
-{
namespace core
{
CommonPolicyEnforce commonEnforce(PolicyEnforce::GetInstance());
} //namespace core
-} //namespace iot
/**
* Samsung Ukraine R&D Center (SRK under a contract between)
* LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
- * Copyright (C) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
*/
/**
- * @file iot_common_enforce.h
+ * @file common_enforce.h
* @brief Implementation of common policy
* @date Created Oct 04, 2017
* @author Mail to: <A HREF="mailto:a.zabolotnyi@samsung.com">Andrey Zabolotnyi, a.zabolotnyi@samsung.com</A>
*/
-#ifndef IOT_COMMON_ENFORCE_H
-#define IOT_COMMON_ENFORCE_H
+#ifndef COMMON_ENFORCE_H
+#define COMMON_ENFORCE_H
#include <string>
-#include "iot_i_policy_group_enforce.h"
-#include "iot_policy_enforce.h"
+#include "i_policy_group_enforce.h"
+#include "policy_enforce.h"
-namespace iot
-{
namespace core
{
};
} //namespace core
-} //namespace iot
-#endif // IOT_COMMON_ENFORCE_H
+#endif // COMMON_ENFORCE_H
#include <unistd.h>
#include <pwd.h>
-#if defined(__BUILD_UBUNTU__) || defined(__MOCK_THIRDPARTY__)
-#include "mock/device-policy-manager.h"
-#else
#include <dpm/device-policy-manager.h>
#include <dpm/bluetooth.h>
#include <dpm/wifi.h>
#include <dpm/application.h>
#include <dpm/security.h>
#include <dpm/firewall.h>
-//#include <dpm/tv.h>
-#endif
#include "logging.h"
+#include "samonitor_tag.h"
#include "dpm_api_mapper.h"
-#define TAG "nmdaemon"
-
-//#define USE_MIS
-
using namespace dpm_api;
using namespace std;
typedef function<int(dpmh, const char*)> ApiStr;
typedef function<int(dpmh, int, const char*)> ApiIntStr;
-#if defined(__BUILD_UBUNTU__) || defined(__MOCK_THIRDPARTY__)
-
-enum {
- DPM_ERROR_NONE,
- DPM_ERROR_INVALID_PARAMETER,
- DPM_ERROR_CONNECTION_REFUSED,
- DPM_ERROR_TIMED_OUT,
- DPM_ERROR_PERMISSION_DENIED,
- DPM_ERROR_NOT_PERMITTED,
- DPM_ERROR_FILE_EXISTS,
- DPM_ERROR_OUT_OF_MEMORY,
- DPM_ERROR_NO_DATA,
-};
-
-#endif
-
-#if !defined(DPM_BUILD_TV) && !defined(__BUILD_UBUNTU__) && !defined(__MOCK_THIRDPARTY__)
-int dpm_restriction_set_usb_client_state(dpmh handle, int allow)
-{
- return 0;
-}
-int dpm_restriction_get_usb_client_state(dpmh handle, int* is_allowed)
-{
- return 0;
-}
-int dpm_restriction_set_sound_state(dpmh handle, int allow)
-{
- return 0;
-}
-int dpm_restriction_get_sound_state(dpmh handle, int* is_allowed)
-{
- return 0;
-}
-int dpm_restriction_set_tuner_state(dpmh handle, int allow)
-{
- return 0;
-}
-int dpm_restriction_get_tuner_state(dpmh handle, int* is_allowed)
-{
- return 0;
-}
-#endif
-
const map<const string, ApiNone> m = {
- {"lockout-screen", dpm_security_lockout_screen},
+ {"lockout-screen", dpm_security_lockout_screen},
};
const map<const string, ApiInt> mi = {
- {"sound", dpm_restriction_set_sound_state},
- {"bluetooth", dpm_restriction_set_bluetooth_mode_change_state},
- {"wifi", dpm_restriction_set_wifi_state},
- {"usb", dpm_restriction_set_usb_client_state},
- {"dtv-tunner", dpm_restriction_set_tuner_state},
-
- {"camera", dpm_restriction_set_camera_state},
- {"microphone", dpm_restriction_set_microphone_state},
- {"location", dpm_restriction_set_location_state},
- {"clipboard", dpm_restriction_set_clipboard_state},
- {"usb-debug", dpm_restriction_set_usb_debugging_state},
- {"wifi-hotspot", dpm_restriction_set_wifi_hotspot_state},
- {"bt-tethering", dpm_restriction_set_bluetooth_tethering_state},
- {"usb-tethering", dpm_restriction_set_usb_tethering_state},
- {"bt-mode-change", dpm_restriction_set_bluetooth_mode_change_state},
+ {"sound", dpm_restriction_set_sound_state},
+ {"bluetooth", dpm_restriction_set_bluetooth_mode_change_state},
+ {"wifi", dpm_restriction_set_wifi_state},
+ {"usb", dpm_restriction_set_usb_client_state},
+ {"dtv-tunner", dpm_restriction_set_tuner_state},
+
+ {"camera", dpm_restriction_set_camera_state},
+ {"microphone", dpm_restriction_set_microphone_state},
+ {"location", dpm_restriction_set_location_state},
+ {"clipboard", dpm_restriction_set_clipboard_state},
+ {"usb-debug", dpm_restriction_set_usb_debugging_state},
+ {"wifi-hotspot", dpm_restriction_set_wifi_hotspot_state},
+ {"bt-tethering", dpm_restriction_set_bluetooth_tethering_state},
+ {"usb-tethering", dpm_restriction_set_usb_tethering_state},
+ {"bt-mode-change", dpm_restriction_set_bluetooth_mode_change_state},
{"bt-desktop-conn", dpm_restriction_set_bluetooth_desktop_connectivity_state},
- {"bt-pairing", dpm_restriction_set_bluetooth_pairing_state},
- {"email", dpm_restriction_set_popimap_email_state},
- {"browser", dpm_restriction_set_browser_state},
- {"bt-mac", dpm_bluetooth_set_device_restriction},
- {"bt-uuid", dpm_bluetooth_set_uuid_restriction},
- {"int-stor-enc", dpm_security_set_internal_storage_encryption},
- {"ext-stor-enc", dpm_security_set_external_storage_encryption},
- {"wifi-profile", dpm_wifi_set_profile_change_restriction},
- {"wifi-network", dpm_wifi_set_network_access_restriction},
+ {"bt-pairing", dpm_restriction_set_bluetooth_pairing_state},
+ {"email", dpm_restriction_set_popimap_email_state},
+ {"browser", dpm_restriction_set_browser_state},
+ {"bt-mac", dpm_bluetooth_set_device_restriction},
+ {"bt-uuid", dpm_bluetooth_set_uuid_restriction},
+ {"int-stor-enc", dpm_security_set_internal_storage_encryption},
+ {"ext-stor-enc", dpm_security_set_external_storage_encryption},
+ {"wifi-profile", dpm_wifi_set_profile_change_restriction},
+ {"wifi-network", dpm_wifi_set_network_access_restriction},
};
const map<const string, ApiStr> ms = {
- {"iptables", dpm_firewall_apply_deny_rules},
+ {"iptables", dpm_firewall_apply_deny_rules},
- {"bt-mac-add", dpm_bluetooth_add_device_to_blacklist},
- {"bt-mac-del", dpm_bluetooth_remove_device_from_blacklist},
- {"bt-uuid-add", dpm_bluetooth_add_uuid_to_blacklist},
- {"bt-uuid-del", dpm_bluetooth_remove_uuid_from_blacklist},
- {"wifi-ssid-add", dpm_wifi_add_ssid_to_blocklist},
- {"wifi-ssid-del", dpm_wifi_remove_ssid_from_blocklist},
+ {"bt-mac-add", dpm_bluetooth_add_device_to_blacklist},
+ {"bt-mac-del", dpm_bluetooth_remove_device_from_blacklist},
+ {"bt-uuid-add", dpm_bluetooth_add_uuid_to_blacklist},
+ {"bt-uuid-del", dpm_bluetooth_remove_uuid_from_blacklist},
+ {"wifi-ssid-add", dpm_wifi_add_ssid_to_blocklist},
+ {"wifi-ssid-del", dpm_wifi_remove_ssid_from_blocklist},
};
#endif
-// {"wipe external data", dpm_security_wipe_data},
-// {"wipe internal data", dpm_security_wipe_data},
-// {"messaging", dpm_restriction_set_messaging_state},
-// {"privil-add", dpm_application_add_privilege_to_blacklist},
-// {"privil-del", dpm_application_remove_privilege_from_blacklist},
-// {"package-set", dpm_application_set_mode_restriction},
-// {"package-unset", dpm_application_unset_mode_restriction},
+// {"wipe external data", dpm_security_wipe_data},
+// {"wipe internal data", dpm_security_wipe_data},
+// {"messaging", dpm_restriction_set_messaging_state},
+// {"privil-add", dpm_application_add_privilege_to_blacklist},
+// {"privil-del", dpm_application_remove_privilege_from_blacklist},
+// {"package-set", dpm_application_set_mode_restriction},
+// {"package-unset", dpm_application_unset_mode_restriction},
Mapper::Mapper() : handle(nullptr)
{
const char* Mapper::getErrorString(dpm_api::ErrorCode err)
{
struct errs {
- dpm_api::ErrorCode code;
- const char* name;
+ dpm_api::ErrorCode code;
+ const char* name;
};
static const errs errs_arr[] = {
- {SUCCESS, "The operation was successful"},
- {INVALID_PARAMETER, "Invalid parameter"},
- {CONNECTION_REFUSED, "Connection refused"},
- {TIMED_OUT, "Time out"},
- {PERMISSION_DENIED, "Access privilege is not sufficient"},
- {NOT_PERMITTED, "Operation not permitted"},
- {FILE_EXISTS, "File exists"},
- {OUT_OF_MEMORY, "Out of memory"},
- {NO_DATA, "No Data"},
- {NOT_INITIALIZED, "Library not initialized"},
- {NAME_NOT_FOUND, "Policy's name not found"},
- {UNKNOWN, "Unknown error"},
+ {SUCCESS, "The operation was successful"},
+ {INVALID_PARAMETER, "Invalid parameter"},
+ {CONNECTION_REFUSED, "Connection refused"},
+ {TIMED_OUT, "Time out"},
+ {PERMISSION_DENIED, "Access privilege is not sufficient"},
+ {NOT_PERMITTED, "Operation not permitted"},
+ {FILE_EXISTS, "File exists"},
+ {OUT_OF_MEMORY, "Out of memory"},
+ {NO_DATA, "No Data"},
+ {NOT_INITIALIZED, "Library not initialized"},
+ {NAME_NOT_FOUND, "Policy's name not found"},
+ {UNKNOWN, "Unknown error"},
};
for (unsigned int i = 0; i < sizeof(errs_arr) / sizeof(errs_arr[0]); ++i) {
/**
* Samsung Ukraine R&D Center (SRK under a contract between)
* LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
- * Copyright (C) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
*/
/**
- * @file iot_i_policy_group_enforce.h
+ * @file i_policy_group_enforce.h
* @brief Interface for policy parsing and applying
* @date Created May 10, 2017
* @author Mail to: <A HREF="mailto:a.volkov@samsung.com">Aleksey Volkov, a.volkov@samsung.com</A>
#include <jsoncpp/json/value.h>
-namespace iot
-{
namespace core
{
} //namespace core
-} //namespace iot
-
#endif //IPOLICY_GRP_APPL_H
+++ /dev/null
-/**
- * Samsung Ukraine R&D Center (SRK under a contract between)
- * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
- * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- */
-/**
- * @file iot_common_enforce.cpp
- * @brief Implementation of common policy
- * @date Created Jul 05, 2016
- * @author Mail to: <A HREF="mailto:a.volkov@samsung.com">Aleksey Volkov, a.volkov@samsung.com</A>
- */
-
-#include "iot_common_enforce.h"
-#include "logging.h"
-#include "dpm_api_mapper.h"
-#include <thread>
-#include <chrono>
-
-#define TAG "nmdaemon"
-
-namespace iot
-{
-namespace core
-{
-
-CommonPolicyEnforce::CommonPolicyEnforce(PolicyEnforce& enforce)
- : m_enforce(enforce)
-{
- LOG_D(TAG, "Register common policy enforce class");
- m_enforce.RegisterGroup(static_cast<IPolicyGroupEnforce*>(this), std::string("common-policies"));
-}
-
-CommonPolicyEnforce::~CommonPolicyEnforce()
-{
-}
-
-bool CommonPolicyEnforce::Init(/*PolicyContext& context*/)
-{
- LOG_D(TAG, "Init common policy applier");
-
- return true;
-}
-
-void CommonPolicyEnforce::Deinit()
-{
- LOG_D(TAG, "De-Init common policy applier");
-}
-
-bool CommonPolicyEnforce::ParseGroup(Json::Value& groupList)
-{
- LOG_D(TAG, "...Start common policies parsing and applying...");
-
- dpm_api::Mapper mapper;
- bool first_time = true;
-
- for (auto& node : groupList) {
- std::string name = node.get("name", "").asString();
- int state = node.get("state", 0).asInt();
- Json::Value items = node.get("items", "");
-
- if (name.empty()) {
- LOG_E(TAG, "skiping policy without name.");
- continue;
- }
-
- dpm_api::ErrorCode err;
-
- std::vector<std::string> v;
- for (auto& item : items) {
- v.push_back(item.asString());
- }
-
- LOG_D(TAG, " Enforce policy [%s] to state %d", name.c_str(), state);
-
- try {
- if (first_time) {
- first_time = false;
- } else {
- std::this_thread::sleep_for(std::chrono::seconds(1));
- }
-
- LOG_D(TAG, " mapper apply %s to state %d", name.c_str(), state);
-
- err = mapper.apply(name, state, v);
-
- if (err != dpm_api::SUCCESS) {
- LOG_E(TAG, " Enforce policy [%s] error: %s", name.c_str(), mapper.getErrorString(err));
- } else {
- LOG_D(TAG, " Enforce policy [%s] ok", name.c_str());
- }
- } catch (std::exception& e) {
- LOG_E(TAG, " Enforce policy [%s] exception: %s", name.c_str(), e.what());
- }
- }
- LOG_D(TAG, "...Finish common policies parsing and applying...");
-
- return true;
-}
-
-CommonPolicyEnforce commonEnforce(PolicyEnforce::GetInstance());
-
-} //namespace core
-} //namespace iot
+++ /dev/null
-/**
- * Samsung Ukraine R&D Center (SRK under a contract between)
- * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
- * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- */
-/**
- * @file iot_common_enforce.h
- * @brief Implementation of common policy
- * @date Created Oct 04, 2017
- * @author Mail to: <A HREF="mailto:a.zabolotnyi@samsung.com">Andrey Zabolotnyi, a.zabolotnyi@samsung.com</A>
- */
-#ifndef IOT_COMMON_ENFORCE_H
-#define IOT_COMMON_ENFORCE_H
-
-#include <string>
-
-#include "iot_i_policy_group_enforce.h"
-#include "iot_policy_enforce.h"
-
-namespace iot
-{
-namespace core
-{
-
-/**
- * @class CommonPolicyEnforce
- * @brief Parse and apply policies to common-policies dpm module
- */
-class CommonPolicyEnforce: public IPolicyGroupEnforce
-{
-
-public:
- /**
- * @brief Constructor
- * @param policy_enforce main policy module
- */
- CommonPolicyEnforce(PolicyEnforce& policy_enforce);
-
- /**
- * @brief Destructor
- */
- virtual ~CommonPolicyEnforce();
-
- /**
- * @brief Initialize common policy module.
- * @return True if success.
- */
- bool Init() override;
-
- /**
- * @brief Deinitialize common policy module.
- */
- void Deinit() override;
-
- /**
- * @brief Parse and apply policy
- * @param policy policy as parsed JSON object
- * @return True in case of success, false otherwise
- */
- bool ParseGroup(Json::Value& policy) override;
-
-private:
- CommonPolicyEnforce() = delete; /**< Copy constructor */
- CommonPolicyEnforce& operator = (const PolicyEnforce&) = delete; /**< = operator copy constructor */
-
-
-private:
- PolicyEnforce& m_enforce; /**< link to PolicyEnforce instance */
-};
-
-} //namespace core
-} //namespace iot
-
-#endif // IOT_COMMON_ENFORCE_H
+++ /dev/null
-/**
- * Samsung Ukraine R&D Center (SRK under a contract between)
- * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
- * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- */
-/**
- * @file iot_i_policy_group_enforce.h
- * @brief Interface for policy parsing and applying
- * @date Created May 10, 2017
- * @author Mail to: <A HREF="mailto:a.volkov@samsung.com">Aleksey Volkov, a.volkov@samsung.com</A>
- */
-
-
-#ifndef IPOLICY_GRP_ENF_H
-#define IPOLICY_GRP_ENF_H
-
-#include <string>
-#include <jsoncpp/json/value.h>
-
-
-namespace iot
-{
-namespace core
-{
-
-/**
- * @interface IPolicyGroupEnforce
- * @brief interface for policy group applier instances. Each policy group should have own applier implementation.
- * Used by PolicyEnforce class
- * @see PolicyEnforce
- */
-class IPolicyGroupEnforce
-{
-
-public:
- /**
- * @brief Destructor
- */
- virtual ~IPolicyGroupEnforce() {};
-
- /**
- * @brief Init function. Used to init context of related module of policy group
- * @return True in case of success, false otherwise
- */
- virtual bool Init() = 0;
-
-
- /**
- * @brief De-Init function. Used to close context of related module of policy group
- */
- virtual void Deinit() = 0;
-
-
- /**
- * @brief Parse and apply policies related to policy group.
- * @param policy policy as parsed JSON object
- * @return True in case of success, false otherwise
- */
- virtual bool ParseGroup(Json::Value& policy) = 0;
-};
-
-
-/**
- * @brief Pointer type of IPolicyGroupEnforce interface object instance
- */
-typedef IPolicyGroupEnforce* IPolicyGroupEnforcePtr;
-
-
-} //namespace core
-} //namespace iot
-
-
-
-#endif //IPOLICY_GRP_APPL_H
+++ /dev/null
-/**
- * Samsung Ukraine R&D Center (SRK under a contract between)
- * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
- * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- */
-/**
- * @file iot_policy_enforce.cpp
- * @brief Policy group agregator
- * @date Created Jul 01, 2016
- * @author Mail to: <A HREF="mailto:a.volkov@samsung.com">Aleksey Volkov, a.volkov@samsung.com</A>
- */
-
-#include "iot_policy_enforce.h"
-#include "iot_tvext_enforce.h"
-
-//#include "tpm_context.h"
-
-#include "logging.h"
-#include <jsoncpp/json/reader.h>
-#include <iostream>
-#define TAG "nmdaemon"
-
-namespace iot
-{
-namespace core
-{
-
-PolicyEnforce::PolicyEnforce()
- : m_policyGroups()
-{
-}
-
-PolicyEnforce::Result
-PolicyEnforce::ParsePolicy(const std::string& jsonString)
-{
- LOG_D(TAG, "PolicyEnforce::ParsePolicy");
- Result result = Result::SUCCESS;
-
- try {
- if (jsonString.empty()) {
- return Result::ERROR_PARSING; //TODO
- }
-
- Json::Value policyGroupList;
- Json::Reader reader;
-
- bool parsingSuccessful = reader.parse(jsonString.c_str(), policyGroupList);
-
- if (!parsingSuccessful || policyGroupList.empty()) {
- return Result::ERROR_PARSING; //TODO
- }
-
- for (auto& node : policyGroupList) {
- std::string groupName = node.get("group", "").asString();
-
- if (groupName.empty()) {
- LOG_E(TAG, "No group node in class");
- return Result::ERROR_PARSING;
- }
-
- PolicyGroupMap::iterator it = m_policyGroups.find(groupName);
-
- if (it == m_policyGroups.end()) {
- //FIXME Set error if error was occured
- LOG_E(TAG, "Group \"%s\" not found", groupName.c_str());
- continue; //TODO
- }
-
- IPolicyGroupEnforce& groupEnforce = *(it->second);
-
- if (!groupEnforce.Init(/*m_context*/)) {
- LOG_E(TAG, "Group \"%s\" init failed", groupName.c_str());
- result = Result::ERROR_GROUP;
- continue; //TODO
- }
-
- Json::Value policiesList = node.get("policies", "");
-
- if (policiesList.empty()) {
- LOG_E(TAG, "No group node in class");
- return Result::ERROR_PARSING;
- }
-
- if (!groupEnforce.ParseGroup(policiesList)) {
- LOG_E(TAG, "Failed to apply policy group: %s", groupName.c_str());
- result = Result::ERROR_GROUP;
- }
-
- groupEnforce.Deinit();
- }
- } catch (std::exception& e) {
- LOG_E(TAG, "Failed to apply policy, exception: %s", e.what());
- LOG_E(TAG, "Policy which caused this exception: %s", jsonString.c_str());
- result = Result::ERROR_PARSING;
- }
-
- return result;
-}
-
-PolicyEnforce& PolicyEnforce::GetInstance()
-{
- static PolicyEnforce policyEnforce;
-
- return policyEnforce;
-}
-
-void PolicyEnforce::RegisterGroup(IPolicyGroupEnforcePtr groupEnforce, const std::string& groupName)
-{
- m_policyGroups[groupName] = groupEnforce;
-}
-
-} //namespace core
-} //namespace iot
-
-
+++ /dev/null
-/**
- * Samsung Ukraine R&D Center (SRK under a contract between)
- * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
- * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- */
-/**
- * @file iot_policy_enforce.h
- * @brief Policy group agregator
- * @date Created Jul 01, 2016
- * @author Mail to: <A HREF="mailto:a.volkov@samsung.com">Aleksey Volkov, a.volkov@samsung.com</A>
- */
-
-
-#ifndef POLICY_ENF_H
-#define POLICY_ENF_H
-
-#include <string>
-#include <map>
-
-#include "iot_i_policy_group_enforce.h"
-
-
-namespace iot
-{
-namespace core
-{
-
-/**
- * @typedef PolicyGroupMap
- * @brief Map of policy group appliers instances
- */
-typedef std::map<std::string, IPolicyGroupEnforcePtr> PolicyGroupMap;
-
-/**
- * @class PolicyEnforce
- * @brief Parses Policy Config xml string and apply policy groups to related parsers
- */
-class PolicyEnforce
-{
-public:
-
- /**
- * @brief Return enum type for PolicyEnforce errors and policy group appliers
- */
- enum class Result {
- SUCCESS = 0, /**< Success result */
- ERROR_PARSING, /**< json data parsing error */
- ERROR_DPM, /**< Error recived from DPM modules */
- ERROR_GROUP /**< Error init or parse a group */
- };
-
-public:
-
- /**
- * @brief Singleton instance recieving method
- * @return Link to PolicyEnforce instance
- */
- static PolicyEnforce& GetInstance();
-
- /**
- * @brief Register policy group applier object instance for defined policy group
- * @param policy_group pointer to the applier instance
- * @param group_name name of the policy group
- */
- void RegisterGroup(IPolicyGroupEnforcePtr policy_group, const std::string& group_name);
-
- /**
- * @brief Parse string policy and apply policy group nodes to related policy group appliers instances
- * @param policy JSON string with policy configuration
- * @return Error code
- */
- Result ParsePolicy(const std::string& policy);
-private:
- PolicyEnforce(); /**< Default constructor */
- PolicyEnforce(const PolicyEnforce&) = delete; /**< Copy constructor */
- PolicyEnforce& operator = (const PolicyEnforce&) = delete; /**< = operator copy constructor*/
-
-private:
- PolicyGroupMap m_policyGroups; /**< Map of policy group appliers instances */
-
-};
-
-} //namespace core
-} //namespace iot
-
-
-
-#endif //POLICY_ENF_H
+++ /dev/null
-/**
- * Samsung Ukraine R&D Center (SRK under a contract between)
- * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
- * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- */
-/**
- * @file iot_tvext_enforce.cpp
- * @brief Implementation of TV policy
- * @date Created Jul 05, 2016
- * @author Mail to: <A HREF="mailto:a.volkov@samsung.com">Aleksey Volkov, a.volkov@samsung.com</A>
- */
-
-
-#include "iot_tvext_enforce.h"
-#include "logging.h"
-#include "dpm_api_mapper.h"
-#include <thread>
-#include <chrono>
-
-#define TAG "nmdaemon"
-
-namespace iot
-{
-namespace core
-{
-
-TvExtPolicyEnforce::TvExtPolicyEnforce(PolicyEnforce& enforce)
- : m_enforce(enforce)
-{
- LOG_D(TAG, "Register tvext policy enforce class");
- m_enforce.RegisterGroup(static_cast<IPolicyGroupEnforce*>(this), std::string("tv-extension"));
-}
-
-TvExtPolicyEnforce::~TvExtPolicyEnforce()
-{
-}
-
-bool TvExtPolicyEnforce::Init()
-{
- LOG_D(TAG, "Init tvext policy applier");
-
- return true;
-}
-
-void TvExtPolicyEnforce::Deinit()
-{
- LOG_D(TAG, "De-Init tvext policy applier");
-}
-
-bool TvExtPolicyEnforce::ParseGroup(Json::Value& groupList)
-{
- LOG_D(TAG, "...Start tvext policies parsing and applying...");
-
- dpm_api::Mapper mapper;
- bool first_time = true;
-
- for (auto& node : groupList) {
- std::string name = node.get("name", "").asString();
- int state = node.get("state", 0).asInt();
- Json::Value items = node.get("items", "");
-
- if (name.empty()) {
- LOG_E(TAG, "skiping policy without name.");
- continue;
- }
-
- dpm_api::ErrorCode err;
-
- std::vector<std::string> v;
- for (auto& item : items) {
- v.push_back(item.asString());
- }
-
- LOG_D(TAG, " Enforce policy [%s] to state %d", name.c_str(), state);
-
- try {
- if (first_time) {
- first_time = false;
- } else {
- std::this_thread::sleep_for(std::chrono::seconds(1));
- }
-
- LOG_D(TAG, " mapper apply %s to state %d", name.c_str(), state);
-
- err = mapper.apply(name, state, v);
-
- if (err != dpm_api::SUCCESS) {
- LOG_E(TAG, " Enforce policy [%s] error: %s", name.c_str(), mapper.getErrorString(err));
- } else {
- LOG_D(TAG, " Enforce policy [%s] ok", name.c_str());
- }
- } catch (std::exception& e) {
- LOG_E(TAG, " Enforce policy [%s] exception: %s", name.c_str(), e.what());
- }
- }
- LOG_D(TAG, "...Finish tvext policies parsing and applying...");
-
- return true;
-}
-
-TvExtPolicyEnforce tvextEnforce(PolicyEnforce::GetInstance());
-
-} //namespace core
-} //namespace iot
+++ /dev/null
-/**
- * Samsung Ukraine R&D Center (SRK under a contract between)
- * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
- * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- */
-/**
- * @file iot_tvext_enforce.h
- * @brief Implementation of TV policy
- * @date Created Jul 05, 2016
- * @author Mail to: <A HREF="mailto:a.volkov@samsung.com">Aleksey Volkov, a.volkov@samsung.com</A>
- */
-
-#ifndef TVEXT_APPL_H
-#define TVEXT_APPL_H
-
-#include <string>
-
-#include "iot_i_policy_group_enforce.h"
-#include "iot_policy_enforce.h"
-
-namespace iot
-{
-namespace core
-{
-
-/**
- * @class TvExtPolicyEnforce
- * @brief Parse and apply policies to tv extension dpm module
- */
-class TvExtPolicyEnforce: public IPolicyGroupEnforce
-{
-
-public:
- /**
- * @brief Default constructor
- * @param policy_enforce main policy module
- */
- TvExtPolicyEnforce(PolicyEnforce& policy_enforce);
-
- /**
- * @brief Destructor
- */
- virtual ~TvExtPolicyEnforce();
-
- /**
- * @brief Init function. Used to init context of TV extensions policy group
- * @return True in case of success, false otherwise
- */
- bool Init() override;
-
- /**
- * @brief De-Init function. Used to close tpm tvext context.
- */
- void Deinit() override;
-
- /**
- * @brief Parse and apply policy to tvext tpm module.
- * @param policy policy as parsed JSON object
- * @return True in case of success, false otherwise
- */
- bool ParseGroup(Json::Value& policy) override;
-
-private:
- TvExtPolicyEnforce() = delete; /**< Copy constructor */
- TvExtPolicyEnforce& operator = (const PolicyEnforce&) = delete; /**< = operator copy constructor */
-
-
-private:
- PolicyEnforce& m_enforce; /**< link to PolicyEnforce instance */
-
-};
-
-} //namespace core
-} //namespace iot
-
-
-
-#endif //TVEXT_ENF_H
+++ /dev/null
-/**
- * Samsung Ukraine R&D Center (SRK under a contract between)
- * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
- * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
- */
-/**
- * @file log.h
- * @brief Logging macro
- * @date Created May 19, 2017
- * @author Mail to: <A HREF="mailto:i.metelytsia@samsung.com">Iurii Metelytsia, i.metelytsia@samsung.com</A>
- * @author Mail to: <A HREF="mailto:d.lomtev@samsung.com">Dmytro Lomtev, d.lomtev@samsung.com</A>
- */
-#include <stdio.h>
-
-/**
- * @brief Error logging
- */
-#ifndef LOG_ERR
-#define LOG_ERR(format, args...) printf("ERR -- %s [%s:%d] " format "\n",__FILE__, __func__, __LINE__, ##args)
-#endif
-
-/**
- * @brief Debug logging
- */
-#ifndef LOG_DBG
-#define LOG_DBG(format, args...) printf("DBG -- %s [%s:%d] " format "\n",__FILE__, __func__, __LINE__, ##args)
-#endif
-
-
-
/**
* Samsung Ukraine R&D Center (SRK under a contract between)
* LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
- * Copyright (C) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
*/
/**
- * @file iot_policy_enforce.cpp
+ * @file policy_enforce.cpp
* @brief Policy group agregator
* @date Created Jul 01, 2016
* @author Mail to: <A HREF="mailto:a.volkov@samsung.com">Aleksey Volkov, a.volkov@samsung.com</A>
*/
-#include "iot_policy_enforce.h"
-#include "iot_tvext_enforce.h"
-
-//#include "tpm_context.h"
-
+#include "policy_enforce.h"
+#include "tvext_enforce.h"
#include "logging.h"
+#include "samonitor_tag.h"
#include <jsoncpp/json/reader.h>
#include <iostream>
-#define TAG "nmdaemon"
-namespace iot
-{
namespace core
{
}
} //namespace core
-} //namespace iot
-
-
/**
* Samsung Ukraine R&D Center (SRK under a contract between)
* LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
- * Copyright (C) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
*/
/**
- * @file iot_policy_enforce.h
+ * @file policy_enforce.h
* @brief Policy group agregator
* @date Created Jul 01, 2016
* @author Mail to: <A HREF="mailto:a.volkov@samsung.com">Aleksey Volkov, a.volkov@samsung.com</A>
#include <string>
#include <map>
-#include "iot_i_policy_group_enforce.h"
+#include "i_policy_group_enforce.h"
-namespace iot
-{
namespace core
{
};
} //namespace core
-} //namespace iot
-
-
#endif //POLICY_ENF_H
/**
* Samsung Ukraine R&D Center (SRK under a contract between)
* LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
- * Copyright (C) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
*/
/**
- * @file iot_tvext_enforce.cpp
+ * @file tvext_enforce.cpp
* @brief Implementation of TV policy
* @date Created Jul 05, 2016
* @author Mail to: <A HREF="mailto:a.volkov@samsung.com">Aleksey Volkov, a.volkov@samsung.com</A>
*/
-#include "iot_tvext_enforce.h"
+#include "tvext_enforce.h"
#include "logging.h"
+#include "samonitor_tag.h"
#include "dpm_api_mapper.h"
#include <thread>
#include <chrono>
-#define TAG "nmdaemon"
-
-namespace iot
-{
namespace core
{
TvExtPolicyEnforce tvextEnforce(PolicyEnforce::GetInstance());
} //namespace core
-} //namespace iot
/**
* Samsung Ukraine R&D Center (SRK under a contract between)
* LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
- * Copyright (C) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
*/
/**
- * @file iot_tvext_enforce.h
+ * @file tvext_enforce.h
* @brief Implementation of TV policy
* @date Created Jul 05, 2016
* @author Mail to: <A HREF="mailto:a.volkov@samsung.com">Aleksey Volkov, a.volkov@samsung.com</A>
#include <string>
-#include "iot_i_policy_group_enforce.h"
-#include "iot_policy_enforce.h"
+#include "i_policy_group_enforce.h"
+#include "policy_enforce.h"
-namespace iot
-{
namespace core
{
};
} //namespace core
-} //namespace iot
-
-
#endif //TVEXT_ENF_H
#include <restservice.h>
#include "main_thread.h"
#include "utils.h"
-#include "iot_policy_enforce.h"
+#include "policy_enforce.h"
#include "proxythread.h"
#include "audit_trail_client.h"
#include "application_service.h"
#include "reportadapter.h"
#include "logging.h"
-#define TAG "SAMonitor"
+#include "samonitor_tag.h"
namespace PH = std::placeholders;
include_directories(BEFORE ../mock)
-FILE(GLOB SRCS *.cpp ../samonitor/*.cpp mock/*.cpp)
+FILE(GLOB SRCS *.cpp ../samonitor/*.cpp ../samonitor/dpm/*.cpp mock/*.cpp)
FILE(GLOB DAEMON_MAIN ../samonitor/main.cpp)
FILE(GLOB DAEMON_MAIN_THREAD ../samonitor/main_thread.cpp)
jsoncpp
boost_system boost_thread boost_serialization
dlog
- dpm
curl
capi-system-info
)
#define DEVICEPOLICYMANAGERMOCK_H
#include <gmock/gmock.h>
-#include "mock/device-policy-manager.h"
+#include <dpm/device-policy-manager.h>
+#include <device_policy_manager_stub.h>
class DPMMock: public DPMInterface
{
}
MOCK_METHOD0(dpm_manager_create, device_policy_manager_h());
- MOCK_METHOD0(dpm_manager_destroy, void());
+ MOCK_METHOD0(dpm_manager_destroy, int());
MOCK_METHOD1(dpm_application_install_package, int(const char* app_name));
MOCK_METHOD1(dpm_application_uninstall_package, int(const char* app_name));
#include <cassert>
-#include "mock/device-policy-manager.h"
+#include <dpm/administration.h>
+#include <dpm/application.h>
+#include <dpm/bluetooth.h>
+#include <dpm/firewall.h>
+#include <dpm/restriction.h>
+#include <dpm/security.h>
+#include <dpm/wifi.h>
-#define TAG "nmdaemon"
+#include "device_policy_manager_stub.h"
namespace
{
device_policy_manager_h dpm_manager_create()
{
assert(dpm_impl != nullptr);
- return dpm_impl->dpm_manager_create();
+ return (device_policy_manager_h)dpm_impl->dpm_manager_create();
}
-void dpm_manager_destroy(device_policy_manager_h handle)
+int dpm_manager_destroy(device_policy_manager_h handle)
{
assert(handle != nullptr);
- handle->dpm_manager_destroy();
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_manager_destroy();
}
int dpm_application_install_package(device_policy_manager_h handle, const char* package_name)
{
assert(handle != nullptr);
- return handle->dpm_application_install_package(package_name);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_application_install_package(package_name);
}
int dpm_application_uninstall_package(device_policy_manager_h handle, const char* package_name)
{
assert(handle != nullptr);
- return handle->dpm_application_uninstall_package(package_name);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_application_uninstall_package(package_name);
}
int dpm_security_lockout_screen(device_policy_manager_h handle)
{
assert(handle != nullptr);
- return handle->dpm_security_lockout_screen();
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_security_lockout_screen();
}
int dpm_restriction_set_camera_state(device_policy_manager_h handle, int state)
{
assert(handle != nullptr);
- return handle->dpm_restriction_set_camera_state(state);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_restriction_set_camera_state(state);
}
int dpm_restriction_set_microphone_state(device_policy_manager_h handle, int state)
{
assert(handle != nullptr);
- return handle->dpm_restriction_set_microphone_state(state);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_restriction_set_microphone_state(state);
}
int dpm_restriction_set_location_state(device_policy_manager_h handle, int state)
{
assert(handle != nullptr);
- return handle->dpm_restriction_set_location_state(state);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_restriction_set_location_state(state);
}
int dpm_restriction_set_external_storage_state(device_policy_manager_h handle, int state)
{
assert(handle != nullptr);
- return handle->dpm_restriction_set_external_storage_state(state);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_restriction_set_external_storage_state(state);
}
int dpm_restriction_set_clipboard_state(device_policy_manager_h handle, int state)
{
assert(handle != nullptr);
- return handle->dpm_restriction_set_clipboard_state(state);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_restriction_set_clipboard_state(state);
}
int dpm_restriction_set_usb_debugging_state(device_policy_manager_h handle, int state)
{
assert(handle != nullptr);
- return handle->dpm_restriction_set_usb_debugging_state(state);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_restriction_set_usb_debugging_state(state);
}
int dpm_restriction_set_wifi_state(device_policy_manager_h handle, int state)
{
assert(handle != nullptr);
- return handle->dpm_restriction_set_wifi_state(state);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_restriction_set_wifi_state(state);
}
int dpm_restriction_set_wifi_hotspot_state(device_policy_manager_h handle, int state)
{
assert(handle != nullptr);
- return handle->dpm_restriction_set_wifi_hotspot_state(state);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_restriction_set_wifi_hotspot_state(state);
}
int dpm_restriction_set_bluetooth_tethering_state(device_policy_manager_h handle, int state)
{
assert(handle != nullptr);
- return handle->dpm_restriction_set_bluetooth_tethering_state(state);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_restriction_set_bluetooth_tethering_state(state);
}
int dpm_restriction_set_usb_tethering_state(device_policy_manager_h handle, int state)
{
assert(handle != nullptr);
- return handle->dpm_restriction_set_usb_tethering_state(state);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_restriction_set_usb_tethering_state(state);
}
int dpm_restriction_set_bluetooth_mode_change_state(device_policy_manager_h handle, int state)
{
assert(handle != nullptr);
- return handle->dpm_restriction_set_bluetooth_mode_change_state(state);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_restriction_set_bluetooth_mode_change_state(state);
}
int dpm_restriction_set_bluetooth_desktop_connectivity_state(device_policy_manager_h handle, int state)
{
assert(handle != nullptr);
- return handle->dpm_restriction_set_bluetooth_desktop_connectivity_state(state);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_restriction_set_bluetooth_desktop_connectivity_state(state);
}
int dpm_restriction_set_bluetooth_pairing_state(device_policy_manager_h handle, int state)
{
assert(handle != nullptr);
- return handle->dpm_restriction_set_bluetooth_pairing_state(state);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_restriction_set_bluetooth_pairing_state(state);
}
int dpm_restriction_set_popimap_email_state(device_policy_manager_h handle, int state)
{
assert(handle != nullptr);
- return handle->dpm_restriction_set_popimap_email_state(state);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_restriction_set_popimap_email_state(state);
}
int dpm_restriction_set_browser_state(device_policy_manager_h handle, int state)
{
assert(handle != nullptr);
- return handle->dpm_restriction_set_browser_state(state);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_restriction_set_browser_state(state);
}
int dpm_bluetooth_set_device_restriction(device_policy_manager_h handle, int state)
{
assert(handle != nullptr);
- return handle->dpm_bluetooth_set_device_restriction(state);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_bluetooth_set_device_restriction(state);
}
int dpm_bluetooth_set_uuid_restriction(device_policy_manager_h handle, int state)
{
assert(handle != nullptr);
- return handle->dpm_bluetooth_set_uuid_restriction(state);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_bluetooth_set_uuid_restriction(state);
}
int dpm_security_set_internal_storage_encryption(device_policy_manager_h handle, int state)
{
assert(handle != nullptr);
- return handle->dpm_security_set_internal_storage_encryption(state);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_security_set_internal_storage_encryption(state);
}
int dpm_security_set_external_storage_encryption(device_policy_manager_h handle, int state)
{
assert(handle != nullptr);
- return handle->dpm_security_set_external_storage_encryption(state);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_security_set_external_storage_encryption(state);
}
int dpm_wifi_set_profile_change_restriction(device_policy_manager_h handle, int state)
{
assert(handle != nullptr);
- return handle->dpm_wifi_set_profile_change_restriction(state);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_wifi_set_profile_change_restriction(state);
}
int dpm_wifi_set_network_access_restriction(device_policy_manager_h handle, int state)
{
assert(handle != nullptr);
- return handle->dpm_wifi_set_network_access_restriction(state);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_wifi_set_network_access_restriction(state);
}
int dpm_bluetooth_add_device_to_blacklist(device_policy_manager_h handle, const char* item)
{
assert(handle != nullptr);
- return handle->dpm_bluetooth_add_device_to_blacklist(item);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_bluetooth_add_device_to_blacklist(item);
}
int dpm_bluetooth_remove_device_from_blacklist(device_policy_manager_h handle, const char* item)
{
assert(handle != nullptr);
- return handle->dpm_bluetooth_remove_device_from_blacklist(item);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_bluetooth_remove_device_from_blacklist(item);
}
int dpm_bluetooth_add_uuid_to_blacklist(device_policy_manager_h handle, const char* item)
{
assert(handle != nullptr);
- return handle->dpm_bluetooth_add_uuid_to_blacklist(item);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_bluetooth_add_uuid_to_blacklist(item);
}
int dpm_bluetooth_remove_uuid_from_blacklist(device_policy_manager_h handle, const char* item)
{
assert(handle != nullptr);
- return handle->dpm_bluetooth_remove_uuid_from_blacklist(item);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_bluetooth_remove_uuid_from_blacklist(item);
}
int dpm_wifi_add_ssid_to_blocklist(device_policy_manager_h handle, const char* item)
{
assert(handle != nullptr);
- return handle->dpm_wifi_add_ssid_to_blocklist(item);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_wifi_add_ssid_to_blocklist(item);
}
int dpm_wifi_remove_ssid_from_blocklist(device_policy_manager_h handle, const char* item)
{
assert(handle != nullptr);
- return handle->dpm_wifi_remove_ssid_from_blocklist(item);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_wifi_remove_ssid_from_blocklist(item);
}
int dpm_security_wipe_data(device_policy_manager_h handle, int state, const char* item)
{
assert(handle != nullptr);
- return handle->dpm_security_wipe_data(state, item);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_security_wipe_data(state, item);
}
int dpm_restriction_set_messaging_state(device_policy_manager_h handle, int state, const char* item)
{
assert(handle != nullptr);
- return handle->dpm_restriction_set_messaging_state(state, item);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_restriction_set_messaging_state(state, item);
}
int dpm_application_add_privilege_to_blacklist(device_policy_manager_h handle, int state, const char* item)
{
assert(handle != nullptr);
- return handle->dpm_application_add_privilege_to_blacklist(state, item);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_application_add_privilege_to_blacklist(state, item);
}
int dpm_application_remove_privilege_from_blacklist(device_policy_manager_h handle, int state, const char* item)
{
assert(handle != nullptr);
- return handle->dpm_application_remove_privilege_from_blacklist(state, item);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_application_remove_privilege_from_blacklist(state, item);
}
int dpm_application_set_mode_restriction(device_policy_manager_h handle, int state, const char* item)
{
assert(handle != nullptr);
- return handle->dpm_application_set_mode_restriction(state, item);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_application_set_mode_restriction(state, item);
}
int dpm_application_unset_mode_restriction(device_policy_manager_h handle, int state, const char* item)
{
assert(handle != nullptr);
- return handle->dpm_application_unset_mode_restriction(state, item);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_application_unset_mode_restriction(state, item);
}
int dpm_firewall_apply_deny_rules(device_policy_manager_h handle, const char* rules)
{
assert(handle != nullptr);
- return handle->dpm_firewall_apply_deny_rules(rules);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_firewall_apply_deny_rules(rules);
}
int dpm_firewall_flush_deny_rules(device_policy_manager_h handle)
{
assert(handle != nullptr);
- return handle->dpm_firewall_flush_deny_rules();
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_firewall_flush_deny_rules();
}
int dpm_restriction_set_usb_client_state(device_policy_manager_h handle, int allow)
{
assert(handle != nullptr);
- return handle->dpm_restriction_set_usb_client_state(allow);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_restriction_set_usb_client_state(allow);
}
int dpm_restriction_get_usb_client_state(device_policy_manager_h handle, int* is_allowed)
{
assert(handle != nullptr);
- return handle->dpm_restriction_get_usb_client_state(is_allowed);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_restriction_get_usb_client_state(is_allowed);
}
int dpm_restriction_set_sound_state(device_policy_manager_h handle, int allow)
{
assert(handle != nullptr);
- return handle->dpm_restriction_set_sound_state(allow);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_restriction_set_sound_state(allow);
}
int dpm_restriction_get_sound_state(device_policy_manager_h handle, int* is_allowed)
{
assert(handle != nullptr);
- return handle->dpm_restriction_get_sound_state(is_allowed);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_restriction_get_sound_state(is_allowed);
}
int dpm_restriction_set_tuner_state(device_policy_manager_h handle, int allow)
{
assert(handle != nullptr);
- return handle->dpm_restriction_set_tuner_state(allow);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_restriction_set_tuner_state(allow);
}
int dpm_restriction_get_tuner_state(device_policy_manager_h handle, int* is_allowed)
{
assert(handle != nullptr);
- return handle->dpm_restriction_get_tuner_state(is_allowed);
+ return reinterpret_cast<DPMInterface*>(handle)->dpm_restriction_get_tuner_state(is_allowed);
}
#ifndef DEVICE_POLICY_MANAGER_H
#define DEVICE_POLICY_MANAGER_H
-#include <cassert>
-
/**
* @brief The DPMInterface class represents supported DPM features
*/
{
}
- virtual DPMInterface* dpm_manager_create()
+ virtual void* dpm_manager_create()
{
return this;
}
- virtual void dpm_manager_destroy() = 0;
+ virtual int dpm_manager_destroy() = 0;
virtual int dpm_application_install_package(const char* app_name) = 0;
virtual int dpm_application_uninstall_package(const char* app_name) = 0;
return 0;
}
- void dpm_manager_destroy() override
+ int dpm_manager_destroy() override
{
+ return 0;
}
int dpm_security_lockout_screen() override
}
};
-typedef DPMInterface* device_policy_manager_h;
-
/**
* @brief Set custom DPM implementation to change DPM functionality. Can be used for testing.
* @param dpm [in] pointer to the object implementing DPMInterface.
*/
void dpm_restore_implementation();
-extern "C"
-{
-
- device_policy_manager_h dpm_manager_create();
-
- void dpm_manager_destroy(device_policy_manager_h handle);
-
- int dpm_application_install_package(device_policy_manager_h handle, const char* package_name);
-
- int dpm_application_uninstall_package(device_policy_manager_h handle, const char* package_name);
-
- int dpm_security_lockout_screen(device_policy_manager_h);
-
- int dpm_restriction_set_camera_state(device_policy_manager_h, int);
- int dpm_restriction_set_microphone_state(device_policy_manager_h, int);
- int dpm_restriction_set_location_state(device_policy_manager_h, int);
- int dpm_restriction_set_external_storage_state(device_policy_manager_h, int);
- int dpm_restriction_set_clipboard_state(device_policy_manager_h, int);
- int dpm_restriction_set_usb_debugging_state(device_policy_manager_h, int);
- int dpm_restriction_set_wifi_state(device_policy_manager_h, int);
- int dpm_restriction_set_wifi_hotspot_state(device_policy_manager_h, int);
- int dpm_restriction_set_bluetooth_tethering_state(device_policy_manager_h, int);
- int dpm_restriction_set_usb_tethering_state(device_policy_manager_h, int);
- int dpm_restriction_set_bluetooth_mode_change_state(device_policy_manager_h, int);
- int dpm_restriction_set_bluetooth_desktop_connectivity_state(device_policy_manager_h, int);
- int dpm_restriction_set_bluetooth_pairing_state(device_policy_manager_h, int);
- int dpm_restriction_set_popimap_email_state(device_policy_manager_h, int);
- int dpm_restriction_set_browser_state(device_policy_manager_h, int);
- int dpm_bluetooth_set_device_restriction(device_policy_manager_h, int);
- int dpm_bluetooth_set_uuid_restriction(device_policy_manager_h, int);
- int dpm_security_set_internal_storage_encryption(device_policy_manager_h, int);
- int dpm_security_set_external_storage_encryption(device_policy_manager_h, int);
- int dpm_wifi_set_profile_change_restriction(device_policy_manager_h, int);
- int dpm_wifi_set_network_access_restriction(device_policy_manager_h, int);
-
- int dpm_bluetooth_add_device_to_blacklist(device_policy_manager_h, const char*);
- int dpm_bluetooth_remove_device_from_blacklist(device_policy_manager_h, const char*);
- int dpm_bluetooth_add_uuid_to_blacklist(device_policy_manager_h, const char*);
- int dpm_bluetooth_remove_uuid_from_blacklist(device_policy_manager_h, const char*);
- int dpm_wifi_add_ssid_to_blocklist(device_policy_manager_h, const char*);
- int dpm_wifi_remove_ssid_from_blocklist(device_policy_manager_h, const char*);
-
- int dpm_security_wipe_data(device_policy_manager_h, int, const char*);
- int dpm_restriction_set_messaging_state(device_policy_manager_h, int, const char*);
- int dpm_application_add_privilege_to_blacklist(device_policy_manager_h, int, const char*);
- int dpm_application_remove_privilege_from_blacklist(device_policy_manager_h, int, const char*);
- int dpm_application_set_mode_restriction(device_policy_manager_h, int, const char*);
- int dpm_application_unset_mode_restriction(device_policy_manager_h, int, const char*);
- int dpm_firewall_apply_deny_rules(device_policy_manager_h handle, const char* rules);
- int dpm_firewall_flush_deny_rules(device_policy_manager_h handle);
-
- int dpm_restriction_set_usb_client_state(device_policy_manager_h handle, int allow);
- int dpm_restriction_get_usb_client_state(device_policy_manager_h handle, int* is_allowed);
- int dpm_restriction_set_sound_state(device_policy_manager_h handle, int allow);
- int dpm_restriction_get_sound_state(device_policy_manager_h handle, int* is_allowed);
- int dpm_restriction_set_tuner_state(device_policy_manager_h handle, int allow);
- int dpm_restriction_get_tuner_state(device_policy_manager_h handle, int* is_allowed);
-
-}
-
#endif // DEVICE_POLICY_MANAGER_H
#ifndef IOT_POLICY_ENFORCE_MOCK_H
#define IOT_POLICY_ENFORCE_MOCK_H
-#include "iot_policy_enforce.h"
+#include "policy_enforce.h"
/**
* @brief The IPolicyGroupEnforceMock class used as mock for policy group
*/
-class IPolicyGroupEnforceMock: public iot::core::IPolicyGroupEnforce
+class IPolicyGroupEnforceMock: public core::IPolicyGroupEnforce
{
public:
MOCK_METHOD0(Init, bool());
--- /dev/null
+#include <jsoncpp/json/reader.h>
+#include "device_policy_manager_mock.h"
+#include "common_enforce.h"
+
+using namespace core;
+using ::testing::_;
+using ::testing::Return;
+
+namespace
+{
+const std::string policy = R"-([{"name":"sound","state":1,"items":[]},
+ {"name":"camera","state":0,"items":[]},
+ {"name":"iptables","state":1,"items":["127.0.0.0/24|UDP|10-1024","1.1.1.1|TCP|80,443","8.8.8.8"]}])-";
+}
+
+TEST(Test_CommonPolicyEnforce, test_ParseGroup)
+{
+ DPMMock dpm;
+
+ CommonPolicyEnforce comm_pe(PolicyEnforce::GetInstance());
+
+ EXPECT_CALL(dpm, dpm_manager_create()).WillOnce(Return(&dpm));
+
+ EXPECT_CALL(dpm, dpm_restriction_set_sound_state(1)).WillOnce(Return(0));
+
+ EXPECT_CALL(dpm, dpm_restriction_set_camera_state(0)).WillOnce(Return(0));
+ EXPECT_CALL(dpm, dpm_manager_destroy()).Times(1);
+ EXPECT_CALL(dpm, dpm_firewall_flush_deny_rules()).WillOnce(Return(0));
+ EXPECT_CALL(dpm, dpm_firewall_apply_deny_rules(_)).Times(3).WillRepeatedly(Return(0));
+
+ EXPECT_TRUE(comm_pe.Init());
+ Json::Value root;
+ Json::Reader reader;
+ ASSERT_TRUE(reader.parse(policy, root));
+ EXPECT_TRUE(comm_pe.ParseGroup(root));
+
+ EXPECT_NO_THROW(comm_pe.Deinit());
+}
using ::testing::_;
using ::testing::Eq;
using ::testing::Return;
+using ::testing::Throw;
#define TAG "Tests"
namespace
{
-const std::chrono::seconds TEST_KEEP_ALIVE(1);
+const std::chrono::milliseconds TEST_KEEP_ALIVE(10);
const std::string TEST_SERVER_ADDRESS{"test-server"};
const std::string TEST_DEVICE_ID{"device-id"};
MOCK_METHOD1(accept, void(const Event& event));
};
+namespace NetworkManager
+{
+
+bool operator==(const SessionInfo& si1, const SessionInfo& si2)
+{
+ return si1.duid == si2.duid && si1.authToken == si2.authToken;
+}
+
+}
+
TEST_F(TestConnection, test_signal)
{
RestServiceMock rest;
+ settings.setDeviceId("");
Connection conn(settings, &rest);
ReportComposer rc;
rc.addEvent(Event(TEST_EVENT_TYPE, TEST_EVENT_DATA1));
rc.addEvent(Event(TEST_EVENT_TYPE, TEST_EVENT_DATA2));
+ SessionInfo checkSessState{"", ""};
+ EXPECT_CALL(rest, registerDevice(Eq(checkSessState), _))
+ .WillOnce(Throw(std::runtime_error("")))
+ .WillOnce(Return(TEST_DEVICE_ID));
EXPECT_CALL(rest, getUpdates(_))
.WillRepeatedly(Return(""));
EXPECT_CALL(rest, sendReport(_, ::testing::Matcher<const Json::Value&>(rc.get())))
conn.signal(ev);
conn.signal(Event(TEST_EVENT_TYPE, TEST_EVENT_DATA2));
- std::this_thread::sleep_for(std::chrono::milliseconds(1100));
+ std::this_thread::sleep_for(std::chrono::milliseconds(70));
conn.stop();
std::thread t(&Connection::loop, &conn);
- std::this_thread::sleep_for(std::chrono::milliseconds(1200));
+ std::this_thread::sleep_for(std::chrono::milliseconds(15));
conn.stop();
ASSERT_EQ(TEST_CONN, (int)ev3.connection);
Event ev4("", "");
+ ASSERT_TRUE(ev4.confirm.empty());
+ ASSERT_EQ(nullptr, ev4.connection);
ev4 = ev3;
ASSERT_EQ(TEST_EVENT_TYPE, ev4.type);
ASSERT_EQ(TEST_EVENT_DATA, ev5.data);
ASSERT_EQ(TEST_EVENT_CONFIRM, ev5.confirm);
ASSERT_EQ(TEST_CONN, (int)ev5.connection);
+
+ Event ev6(TEST_EVENT_TYPE,
+ TEST_EVENT_DATA,
+ TEST_EVENT_CONFIRM);
+
+ ASSERT_EQ(TEST_EVENT_TYPE, ev6.type);
+ ASSERT_EQ(TEST_EVENT_DATA, ev6.data);
+ ASSERT_EQ(TEST_EVENT_CONFIRM, ev6.confirm);
+ ASSERT_EQ(nullptr, ev6.connection);
+
+ Event ev7(TEST_EVENT_TYPE, TEST_EVENT_DATA);
+
+ ASSERT_EQ(TEST_EVENT_TYPE, ev7.type);
+ ASSERT_EQ(TEST_EVENT_DATA, ev7.data);
+ ASSERT_TRUE(ev7.confirm.empty());
+ ASSERT_EQ(nullptr, ev7.connection);
}
TEST(TestEvent, test_propagate)
#include <gmock/gmock.h>
#include <stdexcept>
-#include "iot_policy_enforce_mock.h"
+#include "policy_enforce_mock.h"
-using namespace iot::core;
+using namespace core;
using ::testing::Return;
using ::testing::Throw;
#include <fstream>
#include <cerrno>
#include <capi-system-info/system_info.h>
+#include <ctime>
#include "settings.h"
using namespace NetworkManager;
const char OS_RELEASE_PATH[] = "/etc/os-release";
const std::string DEFAULT_UNKNOWN{"unknown"};
-const std::chrono::seconds DEFAULT_KEEPALIVE(10);
+const std::chrono::milliseconds DEFAULT_KEEPALIVE(10);
const std::string DEVICE_ID{"device-id"};
const std::string DEVICE_SERIAL{"device-serial"};
const std::string SERVER_ADDRESS{"device-id"};
-const std::chrono::seconds KEEPALIVE_TIME(123);
+const std::chrono::milliseconds KEEPALIVE_TIME(123);
std::string randomString(char minc, char maxc, int len)
{
std::string filename = createSettingsFile();
Settings from_ini(filename);
- ASSERT_TRUE(from_ini.isLoaded());
- ASSERT_EQ(SERVER_ADDRESS, from_ini.getServerAddress());
- ASSERT_EQ(DEVICE_ID, from_ini.getDeviceId());
- ASSERT_EQ(DEVICE_SERIAL, from_ini.getSerial());
- ASSERT_EQ(KEEPALIVE_TIME, from_ini.getKeepAliveTimeout());
+ EXPECT_TRUE(from_ini.isLoaded());
+ EXPECT_EQ(SERVER_ADDRESS, from_ini.getServerAddress());
+ EXPECT_EQ(DEVICE_ID, from_ini.getDeviceId());
+ EXPECT_EQ(DEVICE_SERIAL, from_ini.getSerial());
+ EXPECT_EQ(KEEPALIVE_TIME, from_ini.getKeepAliveTimeout());
ASSERT_EQ(0, remove(filename.c_str()));
}
settings.setServerAddress(rstring);
ASSERT_EQ(rstring, settings.getServerAddress());
- std::chrono::seconds timeout(333);
+ std::chrono::milliseconds timeout(333);
settings.setKeepAliveTimeout(timeout);
ASSERT_EQ(timeout, settings.getKeepAliveTimeout());
settings.setSaveFileName(rstring);
ASSERT_EQ(rstring, settings.getSaveFileName());
}
+
+/**
+ * Test Settings class save method
+ * 1. Save with empty file name
+ * 2. Save to temporary file
+ */
+TEST_F(TestSettings, test_save)
+{
+ Settings settings;
+ ASSERT_FALSE(settings.load());
+
+ std::string rstring = randomString('a', 'z', 10);
+ settings.setDeviceId(rstring);
+
+ rstring = randomString('a', 'z', 10);
+ settings.setServerAddress(rstring);
+
+ std::chrono::milliseconds timeout(333);
+ settings.setKeepAliveTimeout(timeout);
+
+ ASSERT_FALSE(settings.save());
+
+ std::string tmpFile("/tmp/test_settings");
+ tmpFile += std::to_string(time(nullptr));
+
+ settings.setSaveFileName(tmpFile);
+ ASSERT_TRUE(settings.save());
+
+ Settings checkSettings(tmpFile);
+
+ ASSERT_EQ(0, remove(tmpFile.c_str()));
+
+ ASSERT_EQ(checkSettings.getDeviceId(), settings.getDeviceId());
+ ASSERT_EQ(checkSettings.getKeepAliveTimeout(), settings.getKeepAliveTimeout());
+ ASSERT_EQ(checkSettings.getSerial(), settings.getSerial());
+ ASSERT_EQ(checkSettings.getServerAddress(), settings.getServerAddress());
+}
--- /dev/null
+#include <jsoncpp/json/reader.h>
+#include "device_policy_manager_mock.h"
+#include "tvext_enforce.h"
+
+using namespace core;
+using ::testing::_;
+using ::testing::Return;
+
+namespace
+{
+const std::string policy = R"-([{"name":"sound","state":1,"items":[]},
+ {"name":"bluetooth","state":1,"items":[]},
+ {"name":"wifi","state":0,"items":[]},
+ {"name":"usb","state":0,"items":[]},
+ {"name":"dtv-tunner","state":1,"items":[]},
+ {"name":"iptables","state":1,"items":["127.0.0.0/24|UDP|10-1024","1.1.1.1|TCP|80,443","8.8.8.8"]}])-";
+}
+
+TEST(Test_TvExtPolicyEnforce, test_ParseGroup)
+{
+ DPMMock dpm;
+
+ TvExtPolicyEnforce tvep(PolicyEnforce::GetInstance());
+
+ EXPECT_CALL(dpm, dpm_manager_create()).WillOnce(Return(&dpm));
+
+ EXPECT_CALL(dpm, dpm_restriction_set_sound_state(1)).WillOnce(Return(0));
+
+ EXPECT_CALL(dpm, dpm_restriction_set_bluetooth_mode_change_state(1)).WillOnce(Return(0));
+ EXPECT_CALL(dpm, dpm_restriction_set_wifi_state(0)).WillOnce(Return(0));
+ EXPECT_CALL(dpm, dpm_restriction_set_usb_client_state(0)).WillOnce(Return(0));
+ EXPECT_CALL(dpm, dpm_restriction_set_tuner_state(1)).WillOnce(Return(0));
+ EXPECT_CALL(dpm, dpm_manager_destroy()).Times(1);
+ EXPECT_CALL(dpm, dpm_firewall_flush_deny_rules()).WillOnce(Return(0));
+ EXPECT_CALL(dpm, dpm_firewall_apply_deny_rules(_)).Times(3).WillRepeatedly(Return(0));
+
+ EXPECT_TRUE(tvep.Init());
+ Json::Value root;
+ Json::Reader reader;
+ ASSERT_TRUE(reader.parse(policy, root));
+ EXPECT_TRUE(tvep.ParseGroup(root));
+
+ EXPECT_NO_THROW(tvep.Deinit());
+}