From: Andrey Zabolotnyi Date: Tue, 15 Aug 2017 13:12:04 +0000 (+0300) Subject: DPM API mapper for TV. New agent X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9e1f7c05917515bf48c3ab6a147cc29e89d2c1c4;p=platform%2Fcore%2Fsecurity%2Fsuspicious-activity-monitor.git DPM API mapper for TV. New agent --- diff --git a/agent/CMakeLists.txt b/agent/CMakeLists.txt index 6b1251e..b0ea3ad 100644 --- a/agent/CMakeLists.txt +++ b/agent/CMakeLists.txt @@ -50,7 +50,7 @@ add_executable(${PROJECT_NAME} ${AGENT_SRCS}) add_subdirectory(tests) -target_link_libraries (${PROJECT_NAME} jsoncpp agent_policy pthread) +target_link_libraries (${PROJECT_NAME} jsoncpp agent_policy pthread dpm) install(TARGETS ${PROJECT_NAME} DESTINATION ${TESTS_DIR}) install(FILES agent.manifest DESTINATION ${MANIFESTDIR}) diff --git a/agent/inc/tvpolicy.h b/agent/inc/tvpolicy.h index cb319bf..b430b75 100644 --- a/agent/inc/tvpolicy.h +++ b/agent/inc/tvpolicy.h @@ -19,33 +19,35 @@ public: TvPolicy(); void setUsbSate(bool on); - Json::Value getUsbPolicy() const; void setWiFiSate(bool on); - Json::Value getWiFiPolicy() const; void setScreenCaptureState(bool on); - Json::Value getScreenCapturePolicy() const; void setBluetoothState(bool on); - Json::Value getBluetoothPolicy() const; - void setIptablesState(bool on); + void setSoundState(bool on); + Json::Value getSoundPolicy() const; - void iptablesAddBlock(const std::string& ip, const IPTablesProtocol proto, const unsigned char ports); + void setTunerState(bool on); + Json::Value getTunerPolicy() const; + void setIptablesState(bool on); + void iptablesAddBlock(const std::string& ip, const IPTablesProtocol proto, const unsigned char ports); void iptablesAddBlock(const std::string& ip, const IPTablesProtocol proto, const std::vector& ports); - void iptablesAddBlockRange(const std::string& ip, const IPTablesProtocol proto, unsigned short start_port, unsigned short end_port); - void iptablesClear(); - void iptablesRemoveBlock(const std::string& ip, IPTablesProtocol proto); + void iptablesAddRule(const std::string& rule) + { + iptables_items.push_back(rule); + } + Json::Value getIptablesPolicy() const; std::string makePolicy() const; @@ -55,9 +57,12 @@ private: bool screen_capture_state; bool bluetooth_state; bool iptables_state; + bool sound_state; + bool tuner_state; std::vector iptables_items; static Json::Value boolPolicy(const std::string& name, bool state); + static Json::Value boolPolicy(const std::string& name, int state); }; #endif // TVPOLICY_H diff --git a/agent/packaging/agent.spec b/agent/packaging/agent.spec index ae1532e..07d84ef 100644 --- a/agent/packaging/agent.spec +++ b/agent/packaging/agent.spec @@ -9,6 +9,7 @@ Source0: %{name}-%{version}.tar.gz BuildRequires: cmake BuildRequires: nwmanager BuildRequires: nwmanager-devel +BuildRequires: pkgconfig(dpm) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(jsoncpp) %if ("%{GTEST_TYPE}" == "mock") @@ -19,7 +20,7 @@ BuildRequires: gtest-devel %endif -%define _tests_dir /usr/apps/agent +%define _tests_dir /usr/bin %define _manifestdir /usr/share/packages %if ("%{GTEST_TYPE}" == "mock") %define _gtest_lib gtest_gmock diff --git a/agent/scripts/build.sh b/agent/scripts/build.sh index c451583..8624ef5 100755 --- a/agent/scripts/build.sh +++ b/agent/scripts/build.sh @@ -46,10 +46,10 @@ echo -e "\n\n" case $DEVICE in - 0) PROFILE=profile.tzmb_3.0_TM2 ; TARGET_ARCH=aarch64 ; GTEST_TYPE="main" ;; - 1) PROFILE=profile.tzmb_3.0_TM1 ; TARGET_ARCH=armv7l ; GTEST_TYPE="main" ;; + 0) PROFILE=profile.tm2_tizen4 ; TARGET_ARCH=aarch64 ; GTEST_TYPE="main" ;; + 1) PROFILE=profile.tm1_tizen4 ; TARGET_ARCH=armv7l ; GTEST_TYPE="main" ;; 2) PROFILE=profile.Main2017_KantM ; TARGET_ARCH=armv7l ; GTEST_TYPE="mock" ;; - 3) PROFILE=profile.Main2017_KantM_4.0 ; TARGET_ARCH=armv7l ; GTEST_TYPE="main" ;; + 3) PROFILE=profile.kantm_tizen4 ; TARGET_ARCH=armv7l ; GTEST_TYPE="main" ;; ?) echo "error: unknown DEVICE number"; exit 1 ;; esac diff --git a/agent/scripts/common.sh b/agent/scripts/common.sh new file mode 100755 index 0000000..1ec2dac --- /dev/null +++ b/agent/scripts/common.sh @@ -0,0 +1,116 @@ +DEVICE_TEMP=${SCRIPT_DIR}/.device +DEVICE= +WORKING_MODE= +SSH_PASSWORD="tizen" + +BLUE='\033[0;34m' +YELLOW='\033[0;33m' +GREEN='\033[0;32m' +RED='\033[0;31m' +NC='\033[0m' + +declare -a KANTM_TV_S=( + "106.125.53.120" + "106.125.53.128" +) + +declare -a RASPBERRY_PI_S=( + "106.125.53.102" + "106.125.38.218" + "106.125.39.133" +) + +declare -a PROFILES_ARRAY=( +"TM2 mobile" +"TM1 mobile / RaspberryPi3" +"Kant TV Tizen 3.0" +"Kant TV Tizen 4.0" +) + +declare -a WM_ARRAY=( +"standard" +"hub" +"primitive" +) + +PROFILES_COUNT=${#PROFILES_ARRAY[@]} +LAST_PROFILE_NUM=$(( ${PROFILES_COUNT} - 1 )) +WM_COUNT=${#WM_ARRAY[@]} + +function readTempFile() { + if [ -e "$DEVICE_TEMP" ] ; then + read -d '\n' -a DEV_INFO < ${DEVICE_TEMP} + DEVICE_PREV=${DEV_INFO[0]} + PREV_TARGET_IP=${DEV_INFO[1]} + PREV_WORKING_MODE=${DEV_INFO[2]} + else + DEVICE_PREV=1 + PREV_TARGET_IP=0 + PREV_WORKING_MODE=0 + fi + + #Debug echo + #echo -e "DEVICE_PREV=$DEVICE_PREV" + #echo -e "PREV_TARGET_IP=$PREV_TARGET_IP" + #echo -e "PREV_WORKING_MODE=$PREV_WORKING_MODE" +} + +function saveTempFile() { + if [ -z "$DEVICE" ]; then + DEVICE=$DEVICE_PREV + fi + if [ -z "$TARGET_IP" ]; then + TARGET_IP=$PREV_TARGET_IP + fi + if [ -z "$WORKING_MODE" ]; then + WORKING_MODE=$PREV_WORKING_MODE + fi + + echo "$DEVICE" > $DEVICE_TEMP + echo "$TARGET_IP" >> $DEVICE_TEMP + echo "$WORKING_MODE" >> $DEVICE_TEMP +} + +function getBuildConfigs { + case $DEVICE in + 0) PROFILE_NAME=tm2_tizen4 ; TARGET_ARCH=aarch64 ; GTEST_TYPE="main" ; KNOWN_DEVICES=() ;; + 1) PROFILE_NAME=tm1_tizen4 ; TARGET_ARCH=armv7l ; GTEST_TYPE="main" ; KNOWN_DEVICES=( ${RASPBERRY_PI_S[@]} ) ;; + 2) PROFILE_NAME=kantm_tizen3 ; TARGET_ARCH=armv7l ; GTEST_TYPE="mock" ; KNOWN_DEVICES=( ${KANTM_TV_S[@]} ) ;; + 3) PROFILE_NAME=kantm_tizen4 ; TARGET_ARCH=armv7l ; GTEST_TYPE="main" ; KNOWN_DEVICES=( ${KANTM_TV_S[@]} ) ;; + *) echo -e "${RED}error: unknown DEVICE number${NC}"; exit 1 ;; + esac + PROFILE=profile.${PROFILE_NAME} +} + +function printDeviceChoice() { + for (( i=0; i<${PROFILES_COUNT}; i++ )); + do + if [ $i -eq $DEVICE ]; then + echo -e "${GREEN}$i) ${PROFILES_ARRAY[$i]}${NC}" + else + echo "$i) ${PROFILES_ARRAY[$i]}" + fi + done + echo "---------------------------------" +} + +function printWorkingModeChoice() { + for (( i=0; i<${WM_COUNT}; i++ )); + do + if [ $i -eq $WORKING_MODE ]; then + echo -e "${GREEN}$i) ${WM_ARRAY[$i]}${NC}" + else + echo "$i) ${WM_ARRAY[$i]}" + fi + done + echo "---------------------------------" +} + +function getWorkingModePackage() { + case $WORKING_MODE in + 0) WORKING_MODE_PACKAGE="" ;; + 1) WORKING_MODE_PACKAGE="-hub" ;; + 2) WORKING_MODE_PACKAGE="-prim" ;; + *) echo -e "${RED}error: unknown working mode${NC}"; exit 1 ;; + esac +} diff --git a/agent/scripts/deploy.sh b/agent/scripts/deploy.sh index 8bcef89..0a42e9e 100755 --- a/agent/scripts/deploy.sh +++ b/agent/scripts/deploy.sh @@ -39,9 +39,9 @@ echo -e "\n\n" case $DEVICE in 0) BUILD_ROOT=GBS_ROOT_3.0_TM2 ; PROFILE=tzmb_3.0_TM2 ; TARGET_ARCH=aarch64 ;; - 1) BUILD_ROOT=GBS_ROOT_3.0_TM1 ; PROFILE=tzmb_3.0_TM1 ; TARGET_ARCH=armv7l ;; + 1) BUILD_ROOT=gbs_root_tm1_tizen4 ; PROFILE=tm1_tizen4 ; TARGET_ARCH=armv7l ;; 2) BUILD_ROOT=GBS_ROOT_3.0 ; PROFILE=Main2017_KantM ; TARGET_ARCH=armv7l ;; - 3) BUILD_ROOT=GBS_ROOT_4.0_kantm ; PROFILE=Main2017_KantM_4.0 ; TARGET_ARCH=armv7l ;; + 3) BUILD_ROOT=kantm_tizen4 ; PROFILE=kantm_tizen4 ; TARGET_ARCH=armv7l ;; ?) echo "error: unknown DEVICE number"; exit 1 ;; esac diff --git a/agent/scripts/gbs.conf b/agent/scripts/gbs.conf index f0bfb3a..17520ae 100644 --- a/agent/scripts/gbs.conf +++ b/agent/scripts/gbs.conf @@ -1,5 +1,5 @@ [general] -profile = repo.tzmb_3.0_TM1_base +profile = profile.tzmb_3.0_TM1 [obs.tizen_org] url = https://api.tizen.org @@ -9,54 +9,48 @@ url = https://168.219.241.169/api user = obs_viewer passwdx = QlpoOTFBWSZTWRLL1vsAAASLgCEgAACSIJmAIAAxA0DQKZMGnqnmfEjRAP8XckU4UJASy9b7 -#############################################z KantM +############################################# Profile [profile.kantm_tizen3] [repo.base_Main2017] -url=http://10.103.211.119/tizen-rsa/tizen-3.0-base-main2017/standard/latest/repos/base/armv7l/packages/ +url = http://10.103.211.119/tizen-rsa/tizen-3.0-base-main2017/standard/latest/repos/base/armv7l/packages/ [repo.srk_Main2017] -url = http://106.125.46.44/repo/kantm/packages/ -[repo.local_Main2017] -url=~/GBS_ROOT_3.0/local/repos/Main2017/armv7l +url = http://52.71.167.178/repo/kantm/packages/ [repo.product_Main2017_KantM] -url=http://10.103.211.119/releases/tizen-3.0-product-main2017/product/KantM/latest/repos/product/armv7l/packages/ -#url=http://10.103.211.119/releases/tizen-3.0-product-main2017/product/KantM/TIZEN-3.0-MAIN2017-KantM-RELEASE_20170419.1/repos/product/armv7l/packages/ +url = http://10.103.211.119/releases/tizen-3.0-product-main2017/product/KantM/latest/repos/product/armv7l/packages/ -[profile.Main2017_KantM] +[profile.kantm_tizen3] obs = obs.tizentv -repos = repo.base_Main2017, repo.srk_Main2017, repo.product_Main2017_KantM, repo.local_Main2017 -buildroot = ~/GBS_ROOT_3.0 +repos = repo.base_Main2017, repo.srk_Main2017, repo.product_Main2017_KantM +buildroot = ~/gbs_root_kantm_tizen3 +############################################# Profile [profile.tm2_tizen4] -############################################# Profile [profile.tzmb_3.0_TM2] - -[repo.tzmb_3.0_TM2_base] +[repo.snapshots_tizen4_arm64_base] url = http://download.tizen.org/snapshots/tizen/base/latest/repos/arm64/packages/ -[repo.tzmb_3.0_TM2_srk] -url = http://106.125.46.44/repo/tm2/packages/ -[repo.tzmb_4.0_unified] +[repo.snapshots_tizen4_tm2_srk] +url = http://52.71.167.178/repo/tm2/packages/ +[repo.snapshots_tizen4] url = http://download.tizen.org/snapshots/tizen/unified/latest/repos/standard/packages/ -[profile.tzmb_3.0_TM2] +[profile.tm2_tizen4] obs = obs.tizen_org -repos = repo.tzmb_3.0_TM2_base, repo.tzmb_3.0_TM2_srk, repo.tzmb_4.0_unified -buildroot = ~/GBS_ROOT_3.0_TM2 +repos = repo.snapshots_tizen4_arm64_base, repo.snapshots_tizen4_tm2_srk, repo.snapshots_tizen4 +buildroot = ~/gbs_root_tm2_tizen4 -############################################# Profile [profile.tzmb_3.0_TM1] +############################################# Profile [profile.tm1_tizen4] -[repo.tzmb_3.0_TM1_base] +[repo.snapshots_tizen4_arm_base] url = http://download.tizen.org/snapshots/tizen/base/latest/repos/arm/packages/ -[repo.tzmb_3.0_TM1_srk] -url = http://106.125.46.44/repo/tm1/packages/ -[repo.tzmb_3.0_TM1] -url = http://download.tizen.org/snapshots/tizen/mobile/latest/repos/arm-wayland/packages/ +[repo.snapshots_tizen4_tm1_srk] +url = http://52.71.167.178/repo/tm1/packages/ -[profile.tzmb_3.0_TM1] +[profile.tm1_tizen4] obs = obs.tizen_org -repos = repo.tzmb_3.0_TM1_base, repo.tzmb_3.0_TM1_srk, repo.tzmb_4.0_unified -buildroot = ~/GBS_ROOT_3.0_TM1 +repos = repo.snapshots_tizen4_arm_base, repo.snapshots_tizen4_tm1_srk, repo.snapshots_tizen4 +buildroot = ~/gbs_root_tm1_tizen4 -############################################# KantM Tizen 4.0 +############################################# Profile [profile.kantm_tizen4] [repo.product_Main2017_KantM_4.0] url=http://10.103.211.119/220svr/releases/adv-tizen-4.0-product-migration/KantM_ATSC/latest/repos/product/armv7l/packages/ @@ -65,7 +59,14 @@ url=http://10.103.211.119/220svr/base/adv-tizen-4.0-base-migration/standard/late [repo.KantM_4.0_srk] url = http://52.71.167.178/repo/kantm4.0/packages/ -[profile.Main2017_KantM_4.0] +#[repo.product_Main2017_KantM_4.0] +#url=http://10.103.211.119/220svr/releases/adv-tizen-4.0-product-migration/KantM_ATSC/latest/repos/product/armv7l/packages/ +#[repo.base_Main2017_KantM_4.0] +#url=http://10.103.211.119/220svr/base/adv-tizen-4.0-base-migration/standard/latest/repos/base/armv7l/packages +#[repo.KantM_4.0_srk] +#url = http://52.71.167.178/repo/kantm4.0/packages/ + +[profile.kantm_tizen4] obs = obs.tizen_org repos = repo.base_Main2017_KantM_4.0, repo.KantM_4.0_srk, repo.product_Main2017_KantM_4.0 -buildroot = ~/GBS_ROOT_4.0_kantm +buildroot = ~/gbs_root_kantm_tizen4 diff --git a/agent/scripts/ssh_deploy.sh b/agent/scripts/ssh_deploy.sh new file mode 100755 index 0000000..a7bca40 --- /dev/null +++ b/agent/scripts/ssh_deploy.sh @@ -0,0 +1,130 @@ +#!/bin/bash + +############################################## +# Definitions +############################################## + +SCRIPT_PATH=$(readlink -m ${0}) +SCRIPT_DIR=${SCRIPT_PATH%/*} +ROOT_DIR=${SCRIPT_DIR}/.. +BUILD_TYPE="RELEASE" +USE_CLEAN= + +source $SCRIPT_DIR/common.sh + + + +############################################## +# Option handler +############################################## + +OPTIONS=`getopt -o 0123456789w: --long working-mode: -n 'Error: ' -- "$@"` +[ $? -eq 0 ] || { + echo "Incorrect options provided" + Usage + exit 1 +} + +eval set -- "$OPTIONS" + +while true; do +case $1 in +-*[0-9]*) + DEVICE=${1:1} + if [ $DEVICE -gt $LAST_PROFILE_NUM ]; then + echo -e "${RED}Wrong profile number: ${DEVICE}${NC}" + exit -1 + fi + shift +;; +"-w" | "--working-mode") + WORKING_MODE=${2} + shift +;; +*) + break +;; +esac +done + + + +############################################## +# Configuring +############################################## + +readTempFile +saveTempFile + +getBuildConfigs +printDeviceChoice + +getWorkingModePackage +printWorkingModeChoice + +if [ -z ${KNOWN_DEVICES} ] ; then + echo "No known devices" + KNOWN_DEVS_LENGTH=0 +else + KNOWN_DEVS_LENGTH=${#KNOWN_DEVICES[@]} + echo "Known devices: ${KNOWN_DEVS_LENGTH}" + for (( i=0; i<${KNOWN_DEVS_LENGTH}; i++ )); + do + if [ "${KNOWN_DEVICES[$i]}" = "$PREV_TARGET_IP" ]; then + echo -e "${GREEN}$i) ${KNOWN_DEVICES[$i]}${NC} <- default" + else + echo "$i) ${KNOWN_DEVICES[$i]}" + fi + done +fi + +if [ -z $PREV_TARGET_IP ] ; then + echo -n "Type target IP address or device number from list of known devices: " +else + echo -n "Type target IP address (default $PREV_TARGET_IP) or device number from list of known devices: " +fi +read TARGET_IP +if [ -z $TARGET_IP ] ; then + if [ -z $PREV_TARGET_IP ] ; then + echo -e "${RED}Target IP is mandatory${NC}" + exit 0 + else + TARGET_IP=$PREV_TARGET_IP + + fi +else + NCHARS=`echo -n "${TARGET_IP}" | wc -m` + if [ ${NCHARS} -eq 1 ] ; then + NUM_RE='^[0-9]+$' + if [[ ! ${TARGET_IP} =~ $NUM_RE ]] || [ ${TARGET_IP} -gt $(( ${KNOWN_DEVS_LENGTH} - 1 )) ] ; then + echo "Wrong option" + exit 1 + else + TARGET_IP=${KNOWN_DEVICES[$TARGET_IP]} + fi + fi +fi + +saveTempFile + +echo "Selected target ${TARGET_IP}" + + + +############################################## +# Main deploy +############################################## + +GBS_RPMS_DIR=~/gbs_root_${PROFILE_NAME}/local/repos/${PROFILE_NAME}/${TARGET_ARCH}/RPMS +TARGET_HOST="root@${TARGET_IP}" + +PASS="sshpass -p ${SSH_PASSWORD}" +${PASS} ssh ${TARGET_HOST} "mount -o remount,rw /" + +${PASS} ssh ${TARGET_HOST} "rpm -e --nodeps \$(rpm -qa 'agent-*')" +${PASS} ssh ${TARGET_HOST} "rm -r /tmp/agent/" +${PASS} ssh ${TARGET_HOST} "mkdir /tmp/agent/" +${PASS} scp ${GBS_RPMS_DIR}/agent-*.rpm ${TARGET_HOST}:/tmp/agent/ +${PASS} ssh ${TARGET_HOST} "rpm -Uvih --nodeps --force /tmp/agent/*" + + diff --git a/agent/src/main.cpp b/agent/src/main.cpp index 4c1bccd..5ecfb20 100644 --- a/agent/src/main.cpp +++ b/agent/src/main.cpp @@ -1,3 +1,12 @@ +//0) PROFILE_NAME=tm2_tizen4 +//1) PROFILE_NAME=tm1_tizen4 +//2) PROFILE_NAME=kantm_tizen3 +//3) PROFILE_NAME=kantm_tizen4 + +#ifndef PROFILE_NAME +# define PROFILE_NAME 3 +#endif + #include #include #include @@ -6,7 +15,32 @@ #include "tvpolicy.h" #include "agentpolicyadapter.h" -// #include "dpm.h" +#include +#include +#include +#include +#include +#include +#if PROFILE_NAME == 3 +# include +#endif + +typedef device_policy_manager_h dpmh; + +//#define directly + +#if PROFILE_NAME != 3 +int dpm_firewall_apply_allow_rules(device_policy_manager_h handle, const char* rules){ return 0; } +int dpm_firewall_flush_allow_rules(device_policy_manager_h handle){ return 0; } +int dpm_firewall_apply_deny_rules(device_policy_manager_h handle, const char* rules){ return 0; } +int dpm_firewall_flush_deny_rules(device_policy_manager_h handle){ return 0; } +int dpm_restriction_set_usb_client_state(device_policy_manager_h handle, int allow){ return 0; } +int dpm_restriction_get_usb_client_state(device_policy_manager_h handle, int *is_allowed){ return 0; } +int dpm_restriction_set_sound_state(device_policy_manager_h handle, int allow){ return 0; } +int dpm_restriction_get_sound_state(device_policy_manager_h handle, int *is_allowed){ return 0; } +int dpm_restriction_set_tuner_state(device_policy_manager_h handle, int allow){ return 0; } +int dpm_restriction_get_tuner_state(device_policy_manager_h handle, int *is_allowed){ return 0; } +#endif using namespace std; @@ -16,7 +50,8 @@ enum class State Show, Usb, WiFi, - ScreenCapture, + Sound, + Tuner, Bluetooth, Iptables, IptablesAdd, @@ -83,6 +118,10 @@ string strip(const string& str) int main(int argc, char* argv[]) { string id; + int res = -1, allow; + bool rule_allow = true; + + dpmh handle = (dpmh)dpm_manager_create(); if (argc > 1) { @@ -96,6 +135,17 @@ int main(int argc, char* argv[]) TvPolicy policy; + dpm_restriction_get_usb_client_state(handle, &allow); + policy.setUsbSate(bool(allow)); + dpm_restriction_get_wifi_state(handle, &allow); + policy.setWiFiSate(bool(allow)); + dpm_restriction_get_sound_state(handle, &allow); + policy.setSoundState(bool(allow)); + dpm_restriction_get_tuner_state(handle, &allow); + policy.setTunerState(bool(allow)); + dpm_restriction_get_bluetooth_mode_change_state(handle, &allow); + policy.setBluetoothState(bool(allow)); + try { State state = State::Main; @@ -110,10 +160,11 @@ int main(int argc, char* argv[]) cout << endl << "Select policy option:" << endl; cout << "\t0 - Show policy" << endl; cout << "\t1 - USB" << endl; - cout << "\t2 - Screen Capture" << endl; + cout << "\t2 - WiFi" << endl; cout << "\t3 - Bluetooth" << endl; cout << "\t4 - IPtables" << endl; - cout << "\t5 - WiFi" << endl; + cout << "\t5 - Sound" << endl; + cout << "\t6 - Tuner" << endl; cout << "\t------------------\n\tq - exit" << endl; cin >> option; @@ -127,7 +178,7 @@ int main(int argc, char* argv[]) state = State::Usb; break; case '2': - state = State::ScreenCapture; + state = State::WiFi; break; case '3': state = State::Bluetooth; @@ -136,13 +187,17 @@ int main(int argc, char* argv[]) state = State::Iptables; break; case '5': - state = State::WiFi; + state = State::Sound; + break; + case '6': + state = State::Tuner; break; case 'q': work = false; break; default: cout << "Unsupported option" << endl << endl; + break; } break; @@ -166,11 +221,25 @@ int main(int argc, char* argv[]) { case '1': policy.setUsbSate(true); +#ifdef directly + res = dpm_restriction_set_usb_client_state(handle, 1); + cout << "set res = " << res << endl; + res = dpm_restriction_get_usb_client_state(handle, &allow); + cout << "get res = " << res << " state = " << allow << endl; +#else applyPolicy(id, policy); +#endif break; case '2': policy.setUsbSate(false); +#ifdef directly + res = dpm_restriction_set_usb_client_state(handle, 0); + cout << "dpm res = " << res << endl; + res = dpm_restriction_get_usb_client_state(handle, &allow); + cout << "get res = " << res << " state = " << allow << endl; +#else applyPolicy(id, policy); +#endif break; case '0': state = State::Main; @@ -180,6 +249,7 @@ int main(int argc, char* argv[]) break; default: cout << "Unsupported option" << endl << endl; + break; } break; @@ -200,11 +270,25 @@ int main(int argc, char* argv[]) { case '1': policy.setWiFiSate(true); - applyPolicy(id, policy); +#ifdef directly + res = dpm_restriction_set_wifi_state(handle, 1); + cout << "set res = " << res << endl; + res = dpm_restriction_get_wifi_state(handle, &allow); + cout << "get res = " << res << " state = " << allow << endl; +#else + applyPolicy(id, policy); +#endif break; case '2': policy.setWiFiSate(false); - applyPolicy(id, policy); +#ifdef directly + res = dpm_restriction_set_wifi_state(handle, 0); + cout << "set res = " << res << endl; + res = dpm_restriction_get_wifi_state(handle, &allow); + cout << "get res = " << res << " state = " << allow << endl; +#else + applyPolicy(id, policy); +#endif break; case '0': state = State::Main; @@ -214,17 +298,18 @@ int main(int argc, char* argv[]) break; default: cout << "Unsupported option" << endl << endl; + break; } break; - case State::ScreenCapture: - cout << endl << "Screen Capture options:" << endl; + case State::Sound: + cout << endl << "Sound options:" << endl; cout << "----------------------" << endl; - cout << policy.getScreenCapturePolicy().toStyledString(); + cout << policy.getSoundPolicy().toStyledString(); cout << "----------------------" << endl; - cout << " 1 - Screen Capture enable" << endl; - cout << " 2 - Screen Capture disable" << endl; + cout << " 1 - Sound enable" << endl; + cout << " 2 - Sound disable" << endl; cout << " 0 - Back" << endl; cout << " ------------------\n\tq - exit" << endl; @@ -233,12 +318,26 @@ int main(int argc, char* argv[]) switch (option) { case '1': - policy.setScreenCaptureState(true); - applyPolicy(id, policy); + policy.setSoundState(true); +#ifdef directly + res = dpm_restriction_set_sound_state(handle, 1); + cout << "set res = " << res << endl; + res = dpm_restriction_get_sound_state(handle, &allow); + cout << "get res = " << res << " state = " << allow << endl; +#else + applyPolicy(id, policy); +#endif break; case '2': - policy.setScreenCaptureState(false); - applyPolicy(id, policy); + policy.setSoundState(false); +#ifdef directly + res = dpm_restriction_set_sound_state(handle, 0); + cout << "set res = " << res << endl; + res = dpm_restriction_get_sound_state(handle, &allow); + cout << "get res = " << res << " state = " << allow << endl; +#else + applyPolicy(id, policy); +#endif break; case '0': state = State::Main; @@ -248,6 +347,56 @@ int main(int argc, char* argv[]) break; default: cout << "Unsupported option" << endl << endl; + break; + } + + break; + + case State::Tuner: + cout << endl << "DTV-Tuner options:" << endl; + cout << "----------------------" << endl; + cout << policy.getTunerPolicy().toStyledString(); + cout << "----------------------" << endl; + cout << " 1 - DTV-Tuner enable" << endl; + cout << " 2 - DTV-Tuner disable" << endl; + cout << " 0 - Back" << endl; + cout << " ------------------\n\tq - exit" << endl; + + cin >> option; + + switch (option) + { + case '1': + policy.setTunerState(true); +#ifdef directly + res = dpm_restriction_set_tuner_state(handle, 1); + cout << "set res = " << res << endl; + res = dpm_restriction_get_tuner_state(handle, &allow); + cout << "get res = " << res << " state = " << allow << endl; +#else + applyPolicy(id, policy); +#endif + break; + case '2': + policy.setTunerState(false); +#ifdef directly + res = dpm_restriction_set_tuner_state(handle, 0); + cout << "set res = " << res << endl; + res = dpm_restriction_get_tuner_state(handle, &allow); + cout << "get res = " << res << " state = " << allow << endl; +#else + applyPolicy(id, policy); +#endif + break; + case '0': + state = State::Main; + break; + case 'q': + work = false; + break; + default: + cout << "Unsupported option" << endl << endl; + break; } break; @@ -267,11 +416,26 @@ int main(int argc, char* argv[]) { case '1': policy.setBluetoothState(true); +#ifdef directly + res = dpm_restriction_set_bluetooth_mode_change_state(handle, 1); + cout << "set res = " << res << endl; + res = dpm_restriction_get_bluetooth_mode_change_state(handle, &allow); + cout << "get res = " << res << " state = " << allow << endl; +#else applyPolicy(id, policy); +#endif + break; case '2': policy.setBluetoothState(false); +#ifdef directly + res = dpm_restriction_set_bluetooth_mode_change_state(handle, 0); + cout << "set res = " << res << endl; + res = dpm_restriction_get_bluetooth_mode_change_state(handle, &allow); + cout << "get res = " << res << " state = " << allow << endl; +#else applyPolicy(id, policy); +#endif break; case '0': state = State::Main; @@ -281,18 +445,17 @@ int main(int argc, char* argv[]) break; default: cout << "Unsupported option" << endl << endl; + break; } break; case State::Iptables: cout << endl << "Iptables options:" << endl; cout << "----------------------" << endl; - cout << policy.getIptablesPolicy().toStyledString(); - cout << "----------------------" << endl; - cout << " 1 - Iptables enable" << endl; - cout << " 2 - Iptables disable" << endl; - cout << " 3 - Iptables add to block list" << endl; - cout << " 4 - Iptables remove from blocklist" << endl; + cout << " 1 - Add allow rule" << endl; + cout << " 2 - Add deny rule" << endl; + cout << " 3 - Flush allow rules" << endl; + cout << " 4 - Flush deny rules" << endl; cout << " 0 - Back" << endl; cout << " ------------------\n\tq - exit" << endl; @@ -301,18 +464,20 @@ int main(int argc, char* argv[]) switch (option) { case '1': - policy.setIptablesState(true); - applyPolicy(id, policy); + state = State::IptablesAdd; + rule_allow = true; break; case '2': - policy.setIptablesState(false); - applyPolicy(id, policy); + state = State::IptablesAdd; + rule_allow = false; break; case '3': - state = State::IptablesAdd; + state = State::IptablesRemove; + rule_allow = true; break; case '4': state = State::IptablesRemove; + rule_allow = false; break; case '0': state = State::Main; @@ -322,56 +487,74 @@ int main(int argc, char* argv[]) break; default: cout << "Unsupported option" << endl << endl; + break; } break; case State::IptablesAdd: { - try - { - cout << endl << "Iptables add to block list:" << endl; - cout << "----------------------" << endl; - cout << " Enter ip address: "; - string ip, ports; - cin >> ip; - unsigned proto; - do - { - cout << " Enter protocol (1 - UDP, 2 - TCP): "; - cin >> proto; - } while (proto != 1 && proto != 2); - - cout << " Enter ports (one value, coma separated list, or range as start-end)" << endl; - cout << " Examples:" << endl << " 1234" << endl << " 80,8080,8000" << endl << " 22-1000" << endl; - cin >> ports; - - auto pos = ports.find('-'); - - IPTablesProtocol p = proto == 1 ? IPTablesProtocol::UDP : IPTablesProtocol::TCP; - - if (pos != string::npos) - { - string start = strip(ports.substr(0, pos)); - string end = strip(ports.substr(pos + 1, string::npos)); - policy.iptablesAddBlockRange(ip, p, std::stoul(start), std::stoul(end)); - } - else - { - auto sports = split(ports, ','); - - std::vector vports; - for (auto sport : sports) - { - vports.push_back((unsigned short)std::stoul(strip(sport))); - } - - policy.iptablesAddBlock(ip, p, vports); - applyPolicy(id, policy); - } - } - catch (...) - { - cout << "Wrong format" << endl; - } + cout << endl << "Iptables add to block list:" << endl; + cout << "----------------------" << endl; + cout << " Enter " << (rule_allow ? "allow" : "deny") << " rule: "; + string rule; + cin >> rule; + +#ifdef directly + if (rule_allow) + res = dpm_firewall_apply_allow_rules(handle, rule.c_str()); + else + res = dpm_firewall_apply_deny_rules(handle, rule.c_str()); + cout << " res = " << res << endl; +#else + policy.iptablesAddRule(rule); + applyPolicy(id, policy); +#endif + +// try +// { +// cout << endl << "Iptables add to block list:" << endl; +// cout << "----------------------" << endl; +// cout << " Enter ip address: "; +// string ip, ports; +// cin >> ip; +// unsigned proto; +// do +// { +// cout << " Enter protocol (1 - UDP, 2 - TCP): "; +// cin >> proto; +// } while (proto != 1 && proto != 2); +// +// cout << " Enter ports (one value, coma separated list, or range as start-end)" << endl; +// cout << " Examples:" << endl << " 1234" << endl << " 80,8080,8000" << endl << " 22-1000" << endl; +// cin >> ports; +// +// auto pos = ports.find('-'); +// +// IPTablesProtocol p = proto == 1 ? IPTablesProtocol::UDP : IPTablesProtocol::TCP; +// +// if (pos != string::npos) +// { +// string start = strip(ports.substr(0, pos)); +// string end = strip(ports.substr(pos + 1, string::npos)); +// policy.iptablesAddBlockRange(ip, p, std::stoul(start), std::stoul(end)); +// } +// else +// { +// auto sports = split(ports, ','); +// +// std::vector vports; +// for (auto sport : sports) +// { +// vports.push_back((unsigned short)std::stoul(strip(sport))); +// } +// +// policy.iptablesAddBlock(ip, p, vports); +// applyPolicy(id, policy); +// } +// } +// catch (...) +// { +// cout << "Wrong format" << endl; +// } } state = State::Iptables; @@ -380,22 +563,34 @@ int main(int argc, char* argv[]) { try { - cout << endl << "Iptables remove from block list:" << endl; - cout << "----------------------" << endl; - cout << " Enter ip address: "; - string ip, ports; - cin >> ip; - unsigned proto; - do - { - cout << " Enter protocol (1 - UDP, 2 - TCP): "; - cin >> proto; - } while (proto != 1 && proto != 2); - - IPTablesProtocol p = proto == 1 ? IPTablesProtocol::UDP : IPTablesProtocol::TCP; - - policy.iptablesRemoveBlock(ip, p); - applyPolicy(id, policy); + cout << endl << "Iptables remove from block list" << endl; +#ifdef directly + if (rule_allow) + res = dpm_firewall_flush_allow_rules(handle); + else + res = dpm_firewall_flush_deny_rules(handle); + cout << " res = " << res << endl; +#else + policy.iptablesClear(); + applyPolicy(id, policy); +#endif + + +// cout << "----------------------" << endl; +// cout << " Enter ip address: "; +// string ip, ports; +// cin >> ip; +// unsigned proto; +// do +// { +// cout << " Enter protocol (1 - UDP, 2 - TCP): "; +// cin >> proto; +// } while (proto != 1 && proto != 2); +// +// IPTablesProtocol p = proto == 1 ? IPTablesProtocol::UDP : IPTablesProtocol::TCP; +// +// policy.iptablesRemoveBlock(ip, p); +// applyPolicy(id, policy); } catch (...) { @@ -412,6 +607,7 @@ int main(int argc, char* argv[]) { cerr << "Exception thrown: " << e.what() << endl; } + if (handle) dpm_manager_destroy((dpmh)handle); cout << "Bye" << endl; diff --git a/agent/src/tvpolicy.cpp b/agent/src/tvpolicy.cpp index bc04577..9ec703e 100644 --- a/agent/src/tvpolicy.cpp +++ b/agent/src/tvpolicy.cpp @@ -6,11 +6,14 @@ const std::string TvPolicy::TV_EXT_GROUP_NAME{"tv-extension"}; TvPolicy::TvPolicy(): - USB_state(true), - screen_capture_state(true), - bluetooth_state(true), - iptables_state(true), - iptables_items() + USB_state(true), + WiFi_state(true), + screen_capture_state(true), + bluetooth_state(true), + iptables_state(true), + sound_state(true), + tuner_state(true), + iptables_items() { } @@ -44,6 +47,26 @@ Json::Value TvPolicy::getScreenCapturePolicy() const return boolPolicy("screen-capture", screen_capture_state); } +void TvPolicy::setSoundState(bool on) +{ + sound_state = on; +} + +Json::Value TvPolicy::getSoundPolicy() const +{ + return boolPolicy("sound", sound_state); +} + +void TvPolicy::setTunerState(bool on) +{ + tuner_state = on; +} + +Json::Value TvPolicy::getTunerPolicy() const +{ + return boolPolicy("dtv-tunner", tuner_state); +} + void TvPolicy::setBluetoothState(bool on) { bluetooth_state = on; @@ -133,7 +156,7 @@ void TvPolicy::iptablesRemoveBlock(const std::string& ip, IPTablesProtocol proto Json::Value TvPolicy::getIptablesPolicy() const { - Json::Value iptables_policy{boolPolicy("iptables", iptables_state)}; + Json::Value iptables_policy{boolPolicy("iptables", int(-1))}; if (!iptables_items.empty()) { @@ -152,18 +175,30 @@ Json::Value TvPolicy::getIptablesPolicy() const std::string TvPolicy::makePolicy() const { Json::Value root; - Json::Value policy; +// Json::Value policy_common; + Json::Value policy_tvext; + +// policy_common["group"] = "common"; + policy_tvext["group"] = "tv-extension"; + +// Json::Value policies_common; +// policies_common.append(getSoundPolicy()); +// policies_common.append(getBluetoothPolicy()); +// policies_common.append(getWiFiPolicy()); +// policies_common.append(getUsbPolicy()); +// policy_common["policies"] = policies_common; +// root.append(policy_common); + + Json::Value policies_tv; + policies_tv.append(getSoundPolicy()); + policies_tv.append(getBluetoothPolicy()); + policies_tv.append(getWiFiPolicy()); + policies_tv.append(getUsbPolicy()); + policies_tv.append(getTunerPolicy()); + policies_tv.append(getIptablesPolicy()); + policy_tvext["policies"] = policies_tv; + root.append(policy_tvext); - policy["group"] = TV_EXT_GROUP_NAME; - - Json::Value policies; - policies.append(getUsbPolicy()); - policies.append(getWiFiPolicy()); - policies.append(getScreenCapturePolicy()); - policies.append(getBluetoothPolicy()); - policies.append(getIptablesPolicy()); - policy["policies"] = policies; - root.append(policy); return root.toStyledString(); } @@ -172,6 +207,16 @@ Json::Value TvPolicy::boolPolicy(const std::string& name, bool state) Json::Value policy; policy["name"] = name; policy["state"] = state ? 1: 0; + policy["items"] = "[]"; + return policy; +} + +Json::Value TvPolicy::boolPolicy(const std::string& name, int state) +{ + Json::Value policy; + policy["name"] = name; + policy["state"] = state; + policy["items"] = "[]"; return policy; } diff --git a/device_core/nmdaemon/agentpolicyservice.cpp b/device_core/nmdaemon/agentpolicyservice.cpp index 13733f4..908a11f 100644 --- a/device_core/nmdaemon/agentpolicyservice.cpp +++ b/device_core/nmdaemon/agentpolicyservice.cpp @@ -39,8 +39,9 @@ pid_t AgentPolicyService::getServicePid() int AgentPolicyService::enforcePolicy(const std::string& agentId, const std::string& jsonData) { - std::cout << "agentId: " << agentId << std::endl; - std::cout << "jsonData: " << jsonData << std::endl; + std::cout << "AgentPolicyService::enforcePolicy()" << std::endl; + std::cout << " agentId: " << agentId << std::endl; + std::cout << " jsonData: " << jsonData << std::endl; /* TODO INSERT HERE POST TO SERVER */ if(m_enforcePolicyHandler != nullptr) diff --git a/device_core/nmdaemon/dpm/dpm_api_mapper.cpp b/device_core/nmdaemon/dpm/dpm_api_mapper.cpp index 0f2ab79..6ae98ec 100644 --- a/device_core/nmdaemon/dpm/dpm_api_mapper.cpp +++ b/device_core/nmdaemon/dpm/dpm_api_mapper.cpp @@ -1,3 +1,13 @@ +//0) PROFILE_NAME=tm2_tizen4 +//1) PROFILE_NAME=tm1_tizen4 +//2) PROFILE_NAME=kantm_tizen3 +//3) PROFILE_NAME=kantm_tizen4 + +#ifndef PROFILE_NAME +//# error "PROFILE_NAME" +# define PROFILE_NAME 3 +#endif + #include #include #include @@ -5,6 +15,8 @@ #include #include #include +#include +#include #ifndef __BUILD_UBUNTU__ #include @@ -13,6 +25,9 @@ #include #include #include +#if PROFILE_NAME == 3 +# include +#endif #endif #include "logging.h" @@ -29,10 +44,10 @@ typedef device_policy_manager_h dpmh; typedef void* dpmh; #endif -typedef function ApiNone; -typedef function ApiInt; -typedef function ApiStr; -typedef function ApiIntStr; +typedef function ApiNone; +typedef function ApiInt; +typedef function ApiStr; +typedef function ApiIntStr; #ifdef __BUILD_UBUNTU__ @@ -95,6 +110,17 @@ int dpm_application_set_mode_restriction(dpmh, int, const char*) { return 0; } int dpm_application_unset_mode_restriction(dpmh, int, const char*) { return 0; } #endif +#if PROFILE_NAME != 3 +int dpm_firewall_apply_deny_rules(device_policy_manager_h handle, const char* rules){ return 0; } +int dpm_firewall_flush_deny_rules(device_policy_manager_h handle){ return 0; } +int dpm_restriction_set_usb_client_state(device_policy_manager_h handle, int allow){ return 0; } +int dpm_restriction_get_usb_client_state(device_policy_manager_h handle, int *is_allowed){ return 0; } +int dpm_restriction_set_sound_state(device_policy_manager_h handle, int allow){ return 0; } +int dpm_restriction_get_sound_state(device_policy_manager_h handle, int *is_allowed){ return 0; } +int dpm_restriction_set_tuner_state(device_policy_manager_h handle, int allow){ return 0; } +int dpm_restriction_get_tuner_state(device_policy_manager_h handle, int *is_allowed){ return 0; } + +#endif int fake_dpm_restriction_set_wifi_state(dpmh h, int allow) { @@ -196,13 +222,17 @@ const map m = { }; const map 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}, - {"usb", fake_dpm_restriction_set_external_storage_state}, {"clipboard", dpm_restriction_set_clipboard_state}, {"usb-debug", dpm_restriction_set_usb_debugging_state}, - {"wifi", fake_dpm_restriction_set_wifi_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}, @@ -220,6 +250,8 @@ const map mi = { }; const map ms = { + {"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}, @@ -242,7 +274,7 @@ const map mis; Mapper::Mapper() : handle(nullptr) { - handle = (dpmh)dpm_manager_create(); +// handle = (dpmh)dpm_manager_create(); } Mapper::~Mapper() @@ -301,8 +333,55 @@ const char* Mapper::get_error_string(dpm_api::error_code err) return "Unknown"; } +pid_t getUidByName(const std::string& name) +{ + long int bufsize = sysconf(_SC_GETPW_R_SIZE_MAX); + if (bufsize == -1) + { + bufsize = 16384; + } + + char* buf = new char[bufsize]; + struct passwd pwd; + struct passwd *result; + + int s = getpwnam_r(name.c_str(), &pwd, buf, bufsize, &result); + pid_t pid = pwd.pw_uid; + delete[] buf; + + if (result == nullptr) + { + if (s == 0) + { + throw std::runtime_error("User not found"); + } + else + { + throw std::runtime_error("Get user info error: " + std::to_string(s)); + } + } + + return pid; +} + dpm_api::error_code Mapper::apply(const std::string &name, const int param, const vector &items) { + dpm_api::error_code res; + + // temporary change user to 'owner' + uid_t root = geteuid(); + uid_t owner = getUidByName("owner"); + (void)setresuid(root, owner, root); + if (!handle) handle = (dpmh)dpm_manager_create(); + res = work(name, param, items); + (void)setresuid(root, root, -1); + return res; +} + +dpm_api::error_code Mapper::work(const std::string &name, const int param, const vector &items) +{ + cout << "### Mapper::apply() " << name << " " << param << endl; + int res = 0; if (!handle) return NOT_INITIALIZED; @@ -317,6 +396,8 @@ dpm_api::error_code Mapper::apply(const std::string &name, const int param, cons auto its = ms.find(name); if (its != ms.end()) { + if (name == "iptables") dpm_firewall_flush_deny_rules((dpmh)handle); + for (auto & item : items) { res = its->second((dpmh)handle, item.c_str()); diff --git a/device_core/nmdaemon/dpm/dpm_api_mapper.h b/device_core/nmdaemon/dpm/dpm_api_mapper.h index 07ec3ab..76eb8f2 100644 --- a/device_core/nmdaemon/dpm/dpm_api_mapper.h +++ b/device_core/nmdaemon/dpm/dpm_api_mapper.h @@ -34,6 +34,9 @@ public: const char* get_error_string(error_code err); error_code apply(const std::string &name, const int param, const std::vector &items); + +protected: + error_code work(const std::string &name, const int param, const std::vector &items); }; } diff --git a/device_core/nmdaemon/nmdaemon.conf b/device_core/nmdaemon/nmdaemon.conf index 63bddc9..45faf90 100644 --- a/device_core/nmdaemon/nmdaemon.conf +++ b/device_core/nmdaemon/nmdaemon.conf @@ -1,9 +1,9 @@ [Cloud] port=5683 # Local SRK -#ip=106.125.46.44 +ip=106.125.46.44 # Amazon -ip=52.71.167.178 +#ip=52.71.167.178 [DSM] # Local SRK uri=http://106.125.46.74:8080/dsm/restapi/ diff --git a/device_core/nmdaemon/policyhandler.cpp b/device_core/nmdaemon/policyhandler.cpp index b8a1985..72229a2 100644 --- a/device_core/nmdaemon/policyhandler.cpp +++ b/device_core/nmdaemon/policyhandler.cpp @@ -12,6 +12,10 @@ void PolicyHandler::enforceCallback(const std::string& agentId, const std::strin { LOG_D(TAG, "Enfore request from agent: %s\n%s", agentId.c_str(), jsonData.c_str()); + std::cout << "PolicyHandler::enforceCallback() Enforce request from agent" << agentId << std::endl; + + //iot::core::PolicyEnforce::GetInstance().ParsePolicy(jsonData); // tmp + OCRepresentation rep; rep.setValue("policy", jsonData); const std::string& device_id = NetworkManager::IoTivity::getInstance()->getDeviceID(); @@ -21,13 +25,18 @@ void PolicyHandler::enforceCallback(const std::string& agentId, const std::strin void PolicyHandler::observeCallback(const HeaderOptions& head_options, const OCRepresentation& rep, const int& ecode, const int& seq_number) { + std::cout << "PolicyHandler::observeCallback" << std::endl; if (ecode == OC_STACK_OK) { std::string policy = rep.getValue("policy"); std::string did = rep.getValue("duid"); std::string route = rep.getValue("route"); + + std::cout << "[Recieved Policy for " << did << "]" << std::endl << policy << std::endl; LOG_D(TAG, "[Recieved Policy for %s]\n%s\n", did.c_str(), policy.c_str()); + const std::string& device_id = NetworkManager::IoTivity::getInstance()->getDeviceID(); + std::cout << "device id: " << device_id << std::endl; if (did == device_id) {