From 8674c6622ba9f5b03aa2f4cc62391e7b4bb0887e Mon Sep 17 00:00:00 2001 From: Lomtev Dmytro Date: Mon, 18 Sep 2017 13:47:10 +0300 Subject: [PATCH] Fixes for the week 37 demo. --- device_core/nmdaemon/agentpolicyservice.cpp | 9 +++++++++ device_core/nmdaemon/audit_trail_client.cpp | 7 ++++++- device_core/nmdaemon/dpm/iot_tvext_enforce.cpp | 2 ++ device_core/nmdaemon/main_thread.cpp | 20 ++++++++++++-------- device_core/nmdaemon/policyhandler.cpp | 5 ++++- device_core/packaging/ioswsec.spec | 4 +--- device_core/utest/CMakeLists.txt | 2 ++ device_core/utest/smack_test.txt | 0 device_core/utest/tests.manifest | 4 ++++ 9 files changed, 40 insertions(+), 13 deletions(-) create mode 100644 device_core/utest/smack_test.txt diff --git a/device_core/nmdaemon/agentpolicyservice.cpp b/device_core/nmdaemon/agentpolicyservice.cpp index 1f9d28e..f769734 100644 --- a/device_core/nmdaemon/agentpolicyservice.cpp +++ b/device_core/nmdaemon/agentpolicyservice.cpp @@ -8,15 +8,20 @@ * @author Mail to: Andriy Gudz, a.gudz@samsung.com */ #include "agentpolicyservice.h" +#include "logging.h" + +#define TAG "nmdaemon" using namespace NMD; AgentPolicyService::AgentPolicyService(EnforcePolicyHandler enforcePolicyHandler /*= nullptr*/) : m_enforcePolicyHandler(enforcePolicyHandler) { + LOG_D(TAG, "AgentPolicyService constructor <-"); service.reset(new rmi::Service(RMI_ADDRESS)); service->registerParametricMethod(this, (int)(AgentPolicyService::enforcePolicy)(std::string, std::string)); service->registerNonparametricMethod(this, (pid_t)(AgentPolicyService::getServicePid)()); + LOG_D(TAG, "AgentPolicyService constructor -> OK"); } AgentPolicyService::~AgentPolicyService() @@ -25,7 +30,9 @@ AgentPolicyService::~AgentPolicyService() void AgentPolicyService::run() { + LOG_D(TAG, "AgentPolicyService::run() <-"); service->start(); + LOG_D(TAG, "AgentPolicyService::run() -> OK"); } void AgentPolicyService::stop() @@ -41,10 +48,12 @@ pid_t AgentPolicyService::getServicePid() int AgentPolicyService::enforcePolicy(const std::string& agentId, const std::string& jsonData) { /* TODO INSERT HERE POST TO SERVER */ + LOG_D(TAG, "AgentPolicyService::enforcePolicy <-"); if (m_enforcePolicyHandler != nullptr) { m_enforcePolicyHandler(agentId, jsonData); } + LOG_D(TAG, "AgentPolicyService::enforcePolicy -> OK"); // return 0 on success return 0; } diff --git a/device_core/nmdaemon/audit_trail_client.cpp b/device_core/nmdaemon/audit_trail_client.cpp index 44bdaba..9098095 100644 --- a/device_core/nmdaemon/audit_trail_client.cpp +++ b/device_core/nmdaemon/audit_trail_client.cpp @@ -10,6 +10,9 @@ #include "report_stub.h" #include "audit_trail_client.h" +#include "logging.h" + +#define TAG "nmdaemon" namespace NMD { @@ -18,6 +21,7 @@ void macLogCallback(const char* log, void* user_data) { assert(log); assert(user_data); + LOG_D(TAG, "MAC log callback: %s", log); AuditTrailClient* client = reinterpret_cast(user_data); assert(client); @@ -28,6 +32,7 @@ void dacLogCallback(const char* log, void* user_data) { assert(log); assert(user_data); + LOG_D(TAG, "DAC log callback: %s", log); AuditTrailClient* client = reinterpret_cast(user_data); assert(client); @@ -124,7 +129,7 @@ void AuditTrailClient::start_auditing() { start_dac_auditing(); start_mac_auditing(); - start_syscall_auditing(); +// start_syscall_auditing(); } void AuditTrailClient::stop_auditing() diff --git a/device_core/nmdaemon/dpm/iot_tvext_enforce.cpp b/device_core/nmdaemon/dpm/iot_tvext_enforce.cpp index 3145b5b..913bd66 100644 --- a/device_core/nmdaemon/dpm/iot_tvext_enforce.cpp +++ b/device_core/nmdaemon/dpm/iot_tvext_enforce.cpp @@ -78,6 +78,8 @@ bool TvExtPolicyEnforce::ParseGroup(Json::Value& groupList) 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) { diff --git a/device_core/nmdaemon/main_thread.cpp b/device_core/nmdaemon/main_thread.cpp index 66ac0e2..5413678 100644 --- a/device_core/nmdaemon/main_thread.cpp +++ b/device_core/nmdaemon/main_thread.cpp @@ -22,6 +22,9 @@ #include "application_service.h" #include "commandhandler.h" +#include "logging.h" +#define TAG "nmdaemon" + using namespace NetworkManager; namespace PH = std::placeholders; @@ -144,8 +147,8 @@ void MainThread::routine() policy_hub_resource->registerResource(); } - CommandHandler command_handler(iotivity, hub, report_handler, policy_handler, proxy_thread, g_working_mode, this); + ControlResource control(&command_handler); if (with_cloud) { @@ -153,9 +156,9 @@ void MainThread::routine() iotivity->publishResources(rhandles); } - AgentPolicyService agent_policy_service(std::bind(&PolicyHandler::enforceCallback, policy_handler.get(), PH::_1, - PH::_2)); - std::thread rmi_thread(&AgentPolicyService::run, &agent_policy_service); +// AgentPolicyService agent_policy_service(std::bind(&PolicyHandler::enforceCallback, policy_handler.get(), PH::_1, +// PH::_2)); +// std::thread rmi_thread(&AgentPolicyService::run, &agent_policy_service); #ifndef __BUILD_UBUNTU__ std::shared_ptr audit_trail_client = nullptr; @@ -163,6 +166,7 @@ void MainThread::routine() if (ApplicationService::get_process_id_by_name("audit-trail") != -1) { audit_trail_client = std::make_shared(iotivity->getDeviceID(), proxy_thread, report_handler, g_working_mode); + LOG_D(TAG, "audit_trail start_auditing"); audit_trail_client->start_auditing(); } #endif @@ -185,11 +189,11 @@ void MainThread::routine() proxy_thread->join(); } - agent_policy_service.stop(); +// agent_policy_service.stop(); - if (rmi_thread.joinable()) { - rmi_thread.join(); - } +// if (rmi_thread.joinable()) { +// rmi_thread.join(); +// } } catch (const std::exception& _e) { write_log("[MAIN_THREADS] error - %s\n", _e.what()); } catch (...) { diff --git a/device_core/nmdaemon/policyhandler.cpp b/device_core/nmdaemon/policyhandler.cpp index 19a5396..50f66bd 100644 --- a/device_core/nmdaemon/policyhandler.cpp +++ b/device_core/nmdaemon/policyhandler.cpp @@ -28,11 +28,14 @@ void PolicyHandler::observeCallback(const HeaderOptions& head_options, const OCR std::string policy = rep.getValue("policy"); std::string did = rep.getValue("duid"); std::string parentUuid = rep.getValue("parentUuid"); - LOG_D(TAG, "[Recieved Policy for %s]\n%s\n", did.c_str(), policy.c_str()); + LOG_D(TAG, "[Recieved Policy for %s]: %s", did.c_str(), policy.c_str()); const std::string& device_id = NetworkManager::IoTivity::getInstance()->getDeviceID(); + if (did == device_id) { + LOG_D(TAG, "Policy for this device"); iot::core::PolicyEnforce::GetInstance().ParsePolicy(policy); } else if (callback && parentUuid == device_id) { + LOG_D(TAG, "Policy for child device"); callback(head_options, rep, ecode, seq_number); } } else { diff --git a/device_core/packaging/ioswsec.spec b/device_core/packaging/ioswsec.spec index 6190a50..643b1c7 100644 --- a/device_core/packaging/ioswsec.spec +++ b/device_core/packaging/ioswsec.spec @@ -113,12 +113,10 @@ Requires: nmlib %description test Google tests -%post -chsmack -a "_" -e "System" %{_tests_dir}/utest - %files test %manifest %{_manifestdir}/tests.manifest %attr(0755,root,root) %{_tests_dir}/utest +%attr(0755,root,root) %{_tests_dir}/smack_test.txt ############################################## # nmdaemon diff --git a/device_core/utest/CMakeLists.txt b/device_core/utest/CMakeLists.txt index 97829a6..9f1dc65 100644 --- a/device_core/utest/CMakeLists.txt +++ b/device_core/utest/CMakeLists.txt @@ -56,6 +56,8 @@ target_link_libraries(${PROJECT_NAME} ${TEST_LINK_LIBRARIES}) install(TARGETS ${PROJECT_NAME} DESTINATION ${TESTS_DIR}) install(FILES tests.manifest DESTINATION ${MANIFESTDIR}) +# FILE used for demo +install(FILES smack_test.txt DESTINATION ${TESTS_DIR}) #file(COPY report_client_db.dat DESTINATION ${TESTS_DIR}) diff --git a/device_core/utest/smack_test.txt b/device_core/utest/smack_test.txt new file mode 100644 index 0000000..e69de29 diff --git a/device_core/utest/tests.manifest b/device_core/utest/tests.manifest index a76fdba..7d53ac4 100644 --- a/device_core/utest/tests.manifest +++ b/device_core/utest/tests.manifest @@ -1,4 +1,8 @@ + + + + -- 2.7.4