From 810e4243029550e4861625943e8bd949023097b8 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Thu, 16 Jun 2016 20:39:59 +0900 Subject: [PATCH 01/16] apply PIE option Change-Id: I7d3271747ff9be58b0f8a46637a8282000c59b3c Signed-off-by: jongmyeongko --- CMakeLists.txt | 23 ++++++++++++----------- src/hybrid/CMakeLists.txt | 1 + src/unit_tests/CMakeLists.txt | 6 +++--- src/wgt/CMakeLists.txt | 1 + src/wgt_backend/CMakeLists.txt | 2 ++ 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 08858fa..20eafb2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,13 +13,18 @@ IF(NOT CMAKE_BUILD_TYPE) ENDIF(NOT CMAKE_BUILD_TYPE) # Compiler flags -SET(CMAKE_C_FLAGS_PROFILING "-O2") -SET(CMAKE_CXX_FLAGS_PROFILING "-O2 -std=c++11") -SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") -SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -std=c++11 -g") -SET(CMAKE_C_FLAGS_RELEASE "-O2 -g") -SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -std=c++11 -g") -SET(CMAKE_CXX_FLAGS_CCOV "-O0 -std=c++11 -g --coverage") +SET(EXTRA_FLAGS "-Wall -Wextra") +SET(CMAKE_C_FLAGS_PROFILING "-O2 ${EXTRA_FLAGS}") +SET(CMAKE_CXX_FLAGS_PROFILING "-O2 -std=c++11 ${EXTRA_FLAGS}") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g ${EXTRA_FLAGS}") +SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -std=c++11 -g ${EXTRA_FLAGS}") +SET(CMAKE_C_FLAGS_RELEASE "-O2 -g ${EXTRA_FLAGS}") +SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -std=c++11 -g ${EXTRA_FLAGS}") +SET(CMAKE_CXX_FLAGS_CCOV "-O0 -std=c++11 -g --coverage ${EXTRA_FLAGS}") + +# Linker flags +SET(EXTRA_LINKER_FLAGS "-Wl,--as-needed") +SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${EXTRA_LINKER_FLAGS}") # Targets SET(TARGET_LIBNAME_WGT "wgt-installer") @@ -30,10 +35,6 @@ SET(TARGET_SMOKE_TEST "smoke-test") SET(TARGET_SMOKE_TEST_HELPER "smoke-test-helper") SET(TARGET_MANIFEST_TEST "manifest-test") -ADD_DEFINITIONS("-Wall") -ADD_DEFINITIONS("-Wextra") -ADD_DEFINITIONS("-fPIE") -ADD_DEFINITIONS("-fPIC") ADD_DEFINITIONS("-DPROJECT_TAG=\"WGT_BACKEND\"") SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/") diff --git a/src/hybrid/CMakeLists.txt b/src/hybrid/CMakeLists.txt index 72cc3d2..ccc7f4a 100644 --- a/src/hybrid/CMakeLists.txt +++ b/src/hybrid/CMakeLists.txt @@ -16,3 +16,4 @@ APPLY_PKG_CONFIG(${TARGET_LIBNAME_HYBRID} PUBLIC # Target - in-package deps TARGET_LINK_LIBRARIES(${TARGET_LIBNAME_HYBRID} PRIVATE ${TARGET_LIBNAME_WGT}) +SET_TARGET_PROPERTIES(${TARGET_LIBNAME_HYBRID} PROPERTIES COMPILE_FLAGS "-fPIC") diff --git a/src/unit_tests/CMakeLists.txt b/src/unit_tests/CMakeLists.txt index 7222f1e..3947045 100644 --- a/src/unit_tests/CMakeLists.txt +++ b/src/unit_tests/CMakeLists.txt @@ -29,9 +29,9 @@ APPLY_PKG_CONFIG(${TARGET_MANIFEST_TEST} PUBLIC # FindGTest module do not sets all needed libraries in GTEST_LIBRARIES and # GTest main libraries is still missing, so additional linking of # GTEST_MAIN_LIBRARIES is needed. -target_link_libraries(${TARGET_SMOKE_TEST} PRIVATE ${TARGET_LIBNAME_WGT} ${TARGET_LIBNAME_HYBRID} ${GTEST_MAIN_LIBRARIES}) -target_link_libraries(${TARGET_SMOKE_TEST_HELPER} PRIVATE ${TARGET_LIBNAME_WGT}) -target_link_libraries(${TARGET_MANIFEST_TEST} PRIVATE ${TARGET_LIBNAME_WGT} ${GTEST_MAIN_LIBRARIES}) +TARGET_LINK_LIBRARIES(${TARGET_SMOKE_TEST} PRIVATE ${TARGET_LIBNAME_WGT} ${TARGET_LIBNAME_HYBRID} ${GTEST_MAIN_LIBRARIES}) +TARGET_LINK_LIBRARIES(${TARGET_SMOKE_TEST_HELPER} PRIVATE ${TARGET_LIBNAME_WGT}) +TARGET_LINK_LIBRARIES(${TARGET_MANIFEST_TEST} PRIVATE ${TARGET_LIBNAME_WGT} ${GTEST_MAIN_LIBRARIES}) INSTALL(TARGETS ${TARGET_SMOKE_TEST} DESTINATION ${BINDIR}/${DESTINATION_DIR}) INSTALL(TARGETS ${TARGET_SMOKE_TEST_HELPER} DESTINATION ${BINDIR}/${DESTINATION_DIR}) diff --git a/src/wgt/CMakeLists.txt b/src/wgt/CMakeLists.txt index ea51011..f45acc5 100644 --- a/src/wgt/CMakeLists.txt +++ b/src/wgt/CMakeLists.txt @@ -42,3 +42,4 @@ APPLY_PKG_CONFIG(${TARGET_LIBNAME_WGT} PUBLIC ENCRYPTION_DEPS Boost ) +SET_TARGET_PROPERTIES(${TARGET_LIBNAME_WGT} PROPERTIES COMPILE_FLAGS "-fPIC") diff --git a/src/wgt_backend/CMakeLists.txt b/src/wgt_backend/CMakeLists.txt index 54f886e..79807f6 100644 --- a/src/wgt_backend/CMakeLists.txt +++ b/src/wgt_backend/CMakeLists.txt @@ -6,6 +6,8 @@ TARGET_INCLUDE_DIRECTORIES(${TARGET_WGT_BACKEND} PUBLIC "${CMAKE_CURRENT_SOURCE_ # Target - in-package deps TARGET_LINK_LIBRARIES(${TARGET_WGT_BACKEND} PRIVATE ${TARGET_LIBNAME_WGT}) TARGET_LINK_LIBRARIES(${TARGET_WGT_BACKEND} PRIVATE ${TARGET_LIBNAME_HYBRID}) +SET_TARGET_PROPERTIES(${TARGET_WGT_BACKEND} PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE") +SET_TARGET_PROPERTIES(${TARGET_WGT_BACKEND} PROPERTIES LINK_FLAGS "-pie") # Install INSTALL(TARGETS ${TARGET_WGT_BACKEND} DESTINATION ${BINDIR}) -- 2.34.1 From e4076b741c3091c2bdebf422dbed000e2b4e59f2 Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Fri, 10 Jun 2016 12:58:58 +0200 Subject: [PATCH 02/16] Implement move request for wgt-backend Check success of commands to verify: wgt-backend -i ${package} wgt-backend -m ${pkgid} -t 1 wgt-backend -m ${pkgid} -t 2 Change-Id: I72ef419c1b4c5f99b3477265a7549a53c5efa838 --- src/wgt/step/configuration/step_parse.cc | 1 + src/wgt/wgt_installer.cc | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/wgt/step/configuration/step_parse.cc b/src/wgt/step/configuration/step_parse.cc index ee937d2..51c86ca 100644 --- a/src/wgt/step/configuration/step_parse.cc +++ b/src/wgt/step/configuration/step_parse.cc @@ -200,6 +200,7 @@ bool StepParse::FillWidgetInfo(manifest_x* manifest) { manifest->appsetting = strdup("false"); manifest->nodisplay_setting = strdup("false"); manifest->preload = strdup("false"); + manifest->installed_storage = strdup("installed_internal"); // For wgt package use the long name for (auto& item : wgt_info->name_set()) { diff --git a/src/wgt/wgt_installer.cc b/src/wgt/wgt_installer.cc index 11b7c9b..bfa2b4e 100644 --- a/src/wgt/wgt_installer.cc +++ b/src/wgt/wgt_installer.cc @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -377,6 +378,16 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); break; } + case ci::RequestType::Move: { + AddStep(pkgmgr_); + AddStep( + ci::configuration::StepParseManifest::ManifestLocation::INSTALLED, + ci::configuration::StepParseManifest::StoreLocation::NORMAL); + AddStep(); + AddStep(); + AddStep(); + break; + } default: { AddStep(); } -- 2.34.1 From 97105afe0264304db009f68f0e10333db77217af Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Mon, 13 Jun 2016 15:39:43 +0200 Subject: [PATCH 03/16] New use of tep steps For internal installation tep is removed with files removal. For external installation tep file must be removed from sd card. Requires: - https://review.tizen.org/gerrit/#/c/74068/ Submit together: - https://review.tizen.org/gerrit/#/c/74068/ - https://review.tizen.org/gerrit/#/c/74293/ - https://review.tizen.org/gerrit/#/c/74294/ Change-Id: I2457b1918d5cb8450c8d1f3f93d42bec77f65d5f --- src/hybrid/hybrid_installer.cc | 11 ++++++----- src/wgt/wgt_installer.cc | 12 +++++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/hybrid/hybrid_installer.cc b/src/hybrid/hybrid_installer.cc index b54c8e5..9b8be50 100644 --- a/src/hybrid/hybrid_installer.cc +++ b/src/hybrid/hybrid_installer.cc @@ -31,7 +31,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -44,7 +46,6 @@ #include #include #include -#include #include #include #include @@ -151,8 +152,7 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep(); - AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -181,6 +181,7 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -221,6 +222,7 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -323,8 +325,7 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr) AddStep(); AddStep(); AddStep(); - AddStep(); - AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); diff --git a/src/wgt/wgt_installer.cc b/src/wgt/wgt_installer.cc index bfa2b4e..7abd4e2 100644 --- a/src/wgt/wgt_installer.cc +++ b/src/wgt/wgt_installer.cc @@ -33,8 +33,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -47,7 +49,6 @@ #include #include #include -#include #include #include #include @@ -149,8 +150,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); - AddStep(); - AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -178,6 +178,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -199,6 +200,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); + AddStep(); AddStep(); AddStep(); break; @@ -232,6 +234,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); @@ -323,8 +326,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); - AddStep(); - AddStep(); + AddStep(); AddStep(); AddStep(); AddStep(); -- 2.34.1 From e82d90ac3087342e09f4dc5d81167aebb32c5119 Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Wed, 25 May 2016 12:39:18 +0200 Subject: [PATCH 04/16] Fix StepParse for tizen:service icon According to 782d65d706b0bc46e12a2e041a9331893c788f6c icon path should be always set with full path. To verify: - install widget with tag and check shared/res/ for icons there should be one per tizen:service and one for widget itself. Change-Id: I58d61c447b88a70de34faabaff81c07133f4cfe4 --- src/wgt/step/configuration/step_parse.cc | 4 +++- src/wgt/step/filesystem/step_wgt_patch_icons.cc | 4 ---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/wgt/step/configuration/step_parse.cc b/src/wgt/step/configuration/step_parse.cc index 51c86ca..5e1a677 100644 --- a/src/wgt/step/configuration/step_parse.cc +++ b/src/wgt/step/configuration/step_parse.cc @@ -343,8 +343,10 @@ bool StepParse::FillServiceApplicationInfo(manifest_x* manifest) { } if (!service_info.icon().empty()) { + bf::path icon_path = context_->root_application_path.get() + / manifest->package / "res" / "wgt" / service_info.icon(); icon_x* icon = reinterpret_cast(calloc(1, sizeof(icon_x))); - icon->text = strdup(service_info.icon().c_str()); + icon->text = strdup(icon_path.c_str()); icon->lang = strdup(DEFAULT_LOCALE); application->icon = g_list_append(application->icon, icon); } diff --git a/src/wgt/step/filesystem/step_wgt_patch_icons.cc b/src/wgt/step/filesystem/step_wgt_patch_icons.cc index d9a1827..5bcb229 100644 --- a/src/wgt/step/filesystem/step_wgt_patch_icons.cc +++ b/src/wgt/step/filesystem/step_wgt_patch_icons.cc @@ -13,10 +13,6 @@ namespace bf = boost::filesystem; namespace bs = boost::system; namespace ci = common_installer; -namespace { -const char kResWgt[] = "res/wgt"; -} // namespace - namespace wgt { namespace filesystem { -- 2.34.1 From c32ebaf7ea6c7b4e1593327e7b6bd3a156a32d10 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Wed, 22 Jun 2016 17:52:03 +0900 Subject: [PATCH 05/16] grant User label to wgt-backend Change-Id: I301c4e2c990a7c3aab377cf9435bb194d8d40868 Signed-off-by: jongmyeongko --- packaging/wgt-backend.manifest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/wgt-backend.manifest b/packaging/wgt-backend.manifest index 85f79f1..18893ce 100644 --- a/packaging/wgt-backend.manifest +++ b/packaging/wgt-backend.manifest @@ -3,6 +3,6 @@ - + -- 2.34.1 From 6099c6684c9f61ffae80084671e6a023a41df03d Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Mon, 13 Jun 2016 16:06:10 +0200 Subject: [PATCH 06/16] Rename backup_paths.h to paths.h Submit together: - https://review.tizen.org/gerrit/74296 - https://review.tizen.org/gerrit/74297 - https://review.tizen.org/gerrit/74298 Change-Id: I9b679eebc05951df0e9c706c1495bf54a376fb9e --- src/unit_tests/smoke_test.cc | 2 +- src/wgt/step/configuration/step_parse.cc | 2 +- src/wgt/step/configuration/step_parse_recovery.cc | 2 +- src/wgt/step/filesystem/step_wgt_prepare_package_directory.cc | 2 +- src/wgt/step/filesystem/step_wgt_update_package_directory.cc | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/unit_tests/smoke_test.cc b/src/unit_tests/smoke_test.cc index 3ab430b..f150590 100644 --- a/src/unit_tests/smoke_test.cc +++ b/src/unit_tests/smoke_test.cc @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/wgt/step/configuration/step_parse.cc b/src/wgt/step/configuration/step_parse.cc index 5e1a677..24c359b 100644 --- a/src/wgt/step/configuration/step_parse.cc +++ b/src/wgt/step/configuration/step_parse.cc @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/wgt/step/configuration/step_parse_recovery.cc b/src/wgt/step/configuration/step_parse_recovery.cc index c01cb41..8ff406d 100644 --- a/src/wgt/step/configuration/step_parse_recovery.cc +++ b/src/wgt/step/configuration/step_parse_recovery.cc @@ -4,7 +4,7 @@ #include "wgt/step/configuration/step_parse_recovery.h" -#include +#include #include namespace { diff --git a/src/wgt/step/filesystem/step_wgt_prepare_package_directory.cc b/src/wgt/step/filesystem/step_wgt_prepare_package_directory.cc index fc4907b..a4e1d6a 100644 --- a/src/wgt/step/filesystem/step_wgt_prepare_package_directory.cc +++ b/src/wgt/step/filesystem/step_wgt_prepare_package_directory.cc @@ -8,7 +8,7 @@ #include #include -#include +#include #include namespace bf = boost::filesystem; diff --git a/src/wgt/step/filesystem/step_wgt_update_package_directory.cc b/src/wgt/step/filesystem/step_wgt_update_package_directory.cc index 0aadad5..17e07d9 100644 --- a/src/wgt/step/filesystem/step_wgt_update_package_directory.cc +++ b/src/wgt/step/filesystem/step_wgt_update_package_directory.cc @@ -8,7 +8,7 @@ #include #include -#include +#include #include namespace bf = boost::filesystem; -- 2.34.1 From 5a036ff4525f485ee44cbc53e05452508a9cbe15 Mon Sep 17 00:00:00 2001 From: Piotr Ganicz Date: Tue, 21 Jun 2016 10:50:51 +0200 Subject: [PATCH 07/16] Refactoring StepParse Change-Id: Ib396f828909c4c114c82876b504c37bdb682a128 --- src/wgt/step/configuration/step_parse.cc | 134 +++++++++++------------ src/wgt/step/configuration/step_parse.h | 11 +- 2 files changed, 74 insertions(+), 71 deletions(-) diff --git a/src/wgt/step/configuration/step_parse.cc b/src/wgt/step/configuration/step_parse.cc index 24c359b..602df3f 100644 --- a/src/wgt/step/configuration/step_parse.cc +++ b/src/wgt/step/configuration/step_parse.cc @@ -82,6 +82,7 @@ void SetApplicationXDefaults(application_x* application) { application->submode = strdup("false"); application->support_disable = strdup("false"); application->ui_gadget = strdup("false"); + application->multiple = strdup("false"); } template @@ -94,7 +95,6 @@ void AppendLabel(T* root, const std::string& label, strdup(locale.c_str()) : strdup(DEFAULT_LOCALE); root->label = g_list_append(root->label, label_item); } - } // namespace namespace wgt { @@ -146,16 +146,16 @@ bool StepParse::FillInstallationInfo(manifest_x* manifest) { } bool StepParse::FillIconPaths(manifest_x* manifest) { - std::shared_ptr app_info = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kTizenApplicationKey)); + auto app_info = + GetManifestDataForKey( + app_keys::kTizenApplicationKey); if (!app_info) { LOG(ERROR) << "Application info manifest data has not been found."; return false; } - std::shared_ptr icons_info = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kIconsKey)); + auto icons_info = + GetManifestDataForKey( + app_keys::kIconsKey); if (icons_info.get()) { for (auto& application_icon : icons_info->icons()) { icon_x* icon = reinterpret_cast (calloc(1, sizeof(icon_x))); @@ -170,9 +170,10 @@ bool StepParse::FillIconPaths(manifest_x* manifest) { } bool StepParse::FillWidgetInfo(manifest_x* manifest) { - std::shared_ptr wgt_info = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kWidgetKey)); + auto wgt_info = + GetManifestDataForKey( + app_keys::kWidgetKey); + if (!wgt_info.get()) { LOG(ERROR) << "Widget info manifest data has not been found."; return false; @@ -203,9 +204,9 @@ bool StepParse::FillWidgetInfo(manifest_x* manifest) { manifest->installed_storage = strdup("installed_internal"); // For wgt package use the long name + application_x* app = + reinterpret_cast(manifest->application->data); for (auto& item : wgt_info->name_set()) { - application_x* app = - reinterpret_cast(manifest->application->data); AppendLabel(app, item.second, item.first); } @@ -219,10 +220,9 @@ bool StepParse::FillWidgetInfo(manifest_x* manifest) { author->lang = strdup(DEFAULT_LOCALE); manifest->author = g_list_append(manifest->author, author); - std::shared_ptr settings_info = - std::static_pointer_cast( - parser_->GetManifestData( - wgt::application_widget_keys::kTizenSettingKey)); + auto settings_info = + GetManifestDataForKey( + wgt::application_widget_keys::kTizenSettingKey); if (settings_info) { switch (settings_info->install_location()) { case wgt::parse::SettingInfo::InstallLocation::AUTO: { @@ -246,18 +246,19 @@ bool StepParse::FillWidgetInfo(manifest_x* manifest) { } bool StepParse::FillMainApplicationInfo(manifest_x* manifest) { - std::shared_ptr app_info = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kTizenApplicationKey)); + auto app_info = + GetManifestDataForKey( + app_keys::kTizenApplicationKey); if (!app_info) { LOG(ERROR) << "Application info manifest data has not been found."; return false; } bool has_watch_catergory = false; bool has_ime = false; - std::shared_ptr category_info = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kTizenCategoryKey)); + auto category_info = + GetManifestDataForKey( + app_keys::kTizenCategoryKey); + if (category_info) { has_watch_catergory = std::find_if(category_info->categories.begin(), category_info->categories.end(), @@ -277,7 +278,6 @@ bool StepParse::FillMainApplicationInfo(manifest_x* manifest) { application->component_type = has_watch_catergory ? strdup("watchapp") : strdup("uiapp"); application->mainapp = strdup("true"); - application->multiple = strdup("false"); application->appid = strdup(app_info->id().c_str()); application->nodisplay = has_ime ? strdup("true") : strdup("false"); application->taskmanage = has_ime ? strdup("false") : strdup("true"); @@ -304,7 +304,8 @@ bool StepParse::FillMainApplicationInfo(manifest_x* manifest) { app_icon->lang = strdup(icon->lang); application->icon = g_list_append(application->icon, app_icon); } - manifest->application = g_list_append(manifest->application, application); + // guarantees that the main app will be at the begining of the list + manifest->application = g_list_insert(manifest->application, application, 0); manifest->package = strdup(app_info->package().c_str()); manifest->mainapp_id = strdup(app_info->id().c_str()); @@ -312,9 +313,9 @@ bool StepParse::FillMainApplicationInfo(manifest_x* manifest) { } bool StepParse::FillServiceApplicationInfo(manifest_x* manifest) { - std::shared_ptr service_list = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kTizenServiceKey)); + auto service_list = + GetManifestDataForKey( + app_keys::kTizenServiceKey); if (!service_list) return true; for (auto& service_info : service_list->services) { @@ -322,7 +323,6 @@ bool StepParse::FillServiceApplicationInfo(manifest_x* manifest) { (calloc(1, sizeof(application_x))); application->component_type = strdup("svcapp"); application->mainapp = strdup("false"); - application->multiple = strdup("false"); application->appid = strdup(service_info.id().c_str()); application->exec = strdup((context_->root_application_path.get() / manifest->package @@ -373,10 +373,9 @@ bool StepParse::FillServiceApplicationInfo(manifest_x* manifest) { } bool StepParse::FillWidgetApplicationInfo(manifest_x* manifest) { - std::shared_ptr appwidget_info = - std::static_pointer_cast( - parser_->GetManifestData( - wgt::application_widget_keys::kTizenAppWidgetFullKey)); + auto appwidget_info = + GetManifestDataForKey( + wgt::application_widget_keys::kTizenAppWidgetFullKey); if (!appwidget_info) return true; for (auto& app_widget : appwidget_info->app_widgets()) { @@ -384,7 +383,6 @@ bool StepParse::FillWidgetApplicationInfo(manifest_x* manifest) { (calloc(1, sizeof(application_x))); application->component_type = strdup("widgetapp"); application->mainapp = strdup("false"); - application->multiple = strdup("false"); application->appid = strdup(app_widget.id.c_str()); application->exec = strdup((context_->root_application_path.get() / manifest->package @@ -439,9 +437,9 @@ bool StepParse::FillBackgroundCategoryInfo(manifest_x* manifest) { } bool StepParse::FillAppControl(manifest_x* manifest) { - std::shared_ptr app_info_list = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kTizenApplicationAppControlsKey)); + auto app_info_list = + GetManifestDataForKey( + app_keys::kTizenApplicationAppControlsKey); application_x* app = reinterpret_cast(manifest->application->data); @@ -459,9 +457,9 @@ bool StepParse::FillAppControl(manifest_x* manifest) { } bool StepParse::FillPrivileges(manifest_x* manifest) { - std::shared_ptr perm_info = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kTizenPermissionsKey)); + auto perm_info = + GetManifestDataForKey( + app_keys::kTizenPermissionsKey); std::set privileges; if (perm_info) privileges = ExtractPrivileges(perm_info); @@ -474,9 +472,9 @@ bool StepParse::FillPrivileges(manifest_x* manifest) { } bool StepParse::FillCategories(manifest_x* manifest) { - std::shared_ptr category_info = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kTizenCategoryKey)); + auto category_info = + GetManifestDataForKey( + app_keys::kTizenCategoryKey); if (!category_info) return true; @@ -490,9 +488,9 @@ bool StepParse::FillCategories(manifest_x* manifest) { } bool StepParse::FillMetadata(manifest_x* manifest) { - std::shared_ptr meta_info = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kTizenMetaDataKey)); + auto meta_info = + GetManifestDataForKey( + app_keys::kTizenMetaDataKey); if (!meta_info) return true; @@ -507,19 +505,18 @@ bool StepParse::FillAppWidget() { WgtBackendData* backend_data = static_cast(context_->backend_data.get()); - std::shared_ptr appwidget_info = - std::static_pointer_cast( - parser_->GetManifestData( - wgt::application_widget_keys::kTizenAppWidgetFullKey)); + auto appwidget_info = + GetManifestDataForKey( + wgt::application_widget_keys::kTizenAppWidgetFullKey); if (appwidget_info) backend_data->appwidgets.set(*appwidget_info); return true; } bool StepParse::FillAccounts(manifest_x* manifest) { - std::shared_ptr account_info = - std::static_pointer_cast( - parser_->GetManifestData(app_keys::kAccountKey)); + auto account_info = + GetManifestDataForKey( + app_keys::kAccountKey); if (!account_info) return true; common_installer::AccountInfo info; @@ -538,8 +535,9 @@ bool StepParse::FillAccounts(manifest_x* manifest) { } bool StepParse::FillImeInfo() { - const auto ime_info = std::static_pointer_cast( - parser_->GetManifestData(app_keys::kTizenImeKey)); + auto ime_info = + GetManifestDataForKey( + app_keys::kAccountKey); if (!ime_info) return true; @@ -645,14 +643,12 @@ common_installer::Step::Status StepParse::process() { } // Copy data from ManifestData to InstallerContext - std::shared_ptr info = - std::static_pointer_cast( - parser_->GetManifestData( - wgt::application_widget_keys::kTizenApplicationKey)); - std::shared_ptr wgt_info = - std::static_pointer_cast( - parser_->GetManifestData( - wgt::application_widget_keys::kTizenWidgetKey)); + auto info = + GetManifestDataForKey( + wgt::application_widget_keys::kTizenApplicationKey); + auto wgt_info = + GetManifestDataForKey( + wgt::application_widget_keys::kTizenWidgetKey); std::string name; const auto& name_set = wgt_info->name_set(); @@ -681,10 +677,9 @@ common_installer::Step::Status StepParse::process() { context_->recovery_info.get().recovery_file->WriteAndCommitFileContent(); } - std::shared_ptr perm_info = - std::static_pointer_cast( - parser_->GetManifestData( - wgt::application_widget_keys::kTizenPermissionsKey)); + auto perm_info = + GetManifestDataForKey( + wgt::application_widget_keys::kTizenPermissionsKey); parser::PermissionSet permissions; if (perm_info) permissions = perm_info->GetAPIPermissions(); @@ -692,10 +687,9 @@ common_installer::Step::Status StepParse::process() { WgtBackendData* backend_data = static_cast(context_->backend_data.get()); - std::shared_ptr settings_info = - std::static_pointer_cast( - parser_->GetManifestData( - wgt::application_widget_keys::kTizenSettingKey)); + auto settings_info = + GetManifestDataForKey( + wgt::application_widget_keys::kTizenSettingKey); if (settings_info) backend_data->settings.set(*settings_info); diff --git a/src/wgt/step/configuration/step_parse.h b/src/wgt/step/configuration/step_parse.h index e7b9357..69015fc 100644 --- a/src/wgt/step/configuration/step_parse.h +++ b/src/wgt/step/configuration/step_parse.h @@ -1,7 +1,6 @@ // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved // Use of this source code is governed by a apache 2.0 license that can be // found in the LICENSE file. - #ifndef WGT_STEP_CONFIGURATION_STEP_PARSE_H_ #define WGT_STEP_CONFIGURATION_STEP_PARSE_H_ @@ -15,6 +14,8 @@ #include #include +#include +#include #include #include #include @@ -75,6 +76,14 @@ class StepParse : public common_installer::Step { ConfigLocation config_location_; bool check_start_file_; + template + std::shared_ptr GetManifestDataForKey(const std::string& key) { + assert(!key.empty()); + static_assert(std::is_base_of::value, + "Type is not base of parser::ManifestData"); + return std::static_pointer_cast(parser_->GetManifestData(key)); + } + STEP_NAME(Parse) }; -- 2.34.1 From da54fd639e7284dd641e5a67579ca2836ade0591 Mon Sep 17 00:00:00 2001 From: Piotr Ganicz Date: Wed, 22 Jun 2016 09:51:31 +0200 Subject: [PATCH 08/16] Fix for update-period Change-Id: Ic8adec0d7bd7aa14a3b5e054aaed67d5cb1d849c --- src/wgt/step/pkgmgr/step_generate_xml.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/wgt/step/pkgmgr/step_generate_xml.cc b/src/wgt/step/pkgmgr/step_generate_xml.cc index 1148642..1173a85 100644 --- a/src/wgt/step/pkgmgr/step_generate_xml.cc +++ b/src/wgt/step/pkgmgr/step_generate_xml.cc @@ -108,7 +108,11 @@ bool WriteWidgetApplicationAttributesAndElements( xmlTextWriterWriteAttribute(writer, BAD_CAST "main", BAD_CAST (appwidget->primary ? "true" : "false")); // NOLINT - xmlTextWriterWriteAttribute(writer, BAD_CAST "update-period", BAD_CAST "0"); + if (!appwidget->update_period.empty()) { + xmlTextWriterWriteAttribute(writer, BAD_CAST "update-period", BAD_CAST + std::to_string(static_cast( + appwidget->update_period.front())).c_str()); + } for (auto& size : appwidget->content_size) { xmlTextWriterStartElement(writer, BAD_CAST "support-size"); @@ -297,7 +301,8 @@ common_installer::Step::Status StepGenerateXml::precheck() { } if (context_->pkgid.get().empty()) { LOG(ERROR) << "pkgid attribute is empty"; - return Step::Status::PACKAGE_NOT_FOUND; } + return Step::Status::PACKAGE_NOT_FOUND; + } if (!context_->manifest_data.get()->application) { LOG(ERROR) << "No application in package"; -- 2.34.1 From 6bbd3f9ddc27487d54bc2441d8cfba9d8bef2345 Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Thu, 16 Jun 2016 14:57:58 +0200 Subject: [PATCH 09/16] Split API in pkgmgr_registration.h Submit together: - https://review.tizen.org/gerrit/75107 - https://review.tizen.org/gerrit/75108 - https://review.tizen.org/gerrit/75109 Change-Id: I259d3aac621443e7985fc2d5aa87e99d5a7bd959 --- src/unit_tests/smoke_test.cc | 6 +++--- src/wgt/wgt_app_query_interface.cc | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/unit_tests/smoke_test.cc b/src/unit_tests/smoke_test.cc index f150590..56dfb15 100644 --- a/src/unit_tests/smoke_test.cc +++ b/src/unit_tests/smoke_test.cc @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include #include @@ -217,13 +217,13 @@ void PackageCheckCleanup(const std::string& pkgid, void ValidatePackage(const std::string& pkgid, const std::vector& appids) { - ASSERT_TRUE(ci::IsPackageInstalled(pkgid, ci::GetRequestMode())); + ASSERT_TRUE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode())); ValidatePackageFS(pkgid, appids); } void CheckPackageNonExistance(const std::string& pkgid, const std::vector& appids) { - ASSERT_FALSE(ci::IsPackageInstalled(pkgid, ci::GetRequestMode())); + ASSERT_FALSE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode())); PackageCheckCleanup(pkgid, appids); } diff --git a/src/wgt/wgt_app_query_interface.cc b/src/wgt/wgt_app_query_interface.cc index e4245cc..912c861 100644 --- a/src/wgt/wgt_app_query_interface.cc +++ b/src/wgt/wgt_app_query_interface.cc @@ -11,7 +11,7 @@ #include #include -#include +#include #include #include #include @@ -107,21 +107,21 @@ bool WgtAppQueryInterface::IsAppInstalledByArgv(int argc, char** argv) { return false; // argument from commandline is package id - if (ci::IsPackageInstalled(arg, ci::GetRequestMode())) + if (ci::QueryIsPackageInstalled(arg, ci::GetRequestMode())) return true; // argument from commandline is path to file std::string pkg_id = GetPkgIdFromPath(arg); if (pkg_id.empty()) return false; - return ci::IsPackageInstalled(pkg_id, ci::GetRequestMode()); + return ci::QueryIsPackageInstalled(pkg_id, ci::GetRequestMode()); } bool WgtAppQueryInterface::IsHybridApplication(int argc, char** argv) { std::string arg = GetInstallationRequestInfo(argc, argv); if (arg.find("apps_rw/recovery-") != std::string::npos) arg = ReadPkgidFromRecovery(arg); - if (ci::IsPackageInstalled(arg, ci::GetRequestMode())) { + if (ci::QueryIsPackageInstalled(arg, ci::GetRequestMode())) { bf::path package_directory(ci::GetRootAppPath(false)); if (bf::exists(package_directory / arg / kTizenManifestLocation) && bf::exists(package_directory / arg / kHybridConfigLocation)) -- 2.34.1 From 70f676c0d426d55dc0dc7201f83e7c4e9aac1c06 Mon Sep 17 00:00:00 2001 From: Arkadiusz Szulakiewicz Date: Wed, 22 Jun 2016 14:29:06 +0200 Subject: [PATCH 10/16] Add 'multiple-accounts-support' attribute for false values Change-Id: I16f212ec25689115c890f5688cdd7f8657cbebda --- src/wgt/step/pkgmgr/step_generate_xml.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/wgt/step/pkgmgr/step_generate_xml.cc b/src/wgt/step/pkgmgr/step_generate_xml.cc index 1173a85..8e92818 100644 --- a/src/wgt/step/pkgmgr/step_generate_xml.cc +++ b/src/wgt/step/pkgmgr/step_generate_xml.cc @@ -504,6 +504,10 @@ void StepGenerateXml::GenerateAccount(xmlTextWriterPtr writer) { xmlTextWriterWriteAttribute(writer, BAD_CAST "multiple-accounts-support", BAD_CAST "true"); + else + xmlTextWriterWriteAttribute(writer, + BAD_CAST "multiple-accounts-support", + BAD_CAST "false"); for (auto& icon_pair : account.icon_paths) { xmlTextWriterStartElement(writer, BAD_CAST "icon"); if (icon_pair.first == "AccountSmall") -- 2.34.1 From a90c5e7a6e9bd7302109e7e91f0d44b6ce67cc96 Mon Sep 17 00:00:00 2001 From: JongHeon Choi Date: Mon, 27 Jun 2016 13:26:44 +0900 Subject: [PATCH 11/16] Modify nodisplay value of widget-application Change-Id: I1cc298f5761d9bdd0b446a7cc06a937244f83187 --- src/wgt/step/configuration/step_parse.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wgt/step/configuration/step_parse.cc b/src/wgt/step/configuration/step_parse.cc index 602df3f..df06790 100644 --- a/src/wgt/step/configuration/step_parse.cc +++ b/src/wgt/step/configuration/step_parse.cc @@ -388,7 +388,7 @@ bool StepParse::FillWidgetApplicationInfo(manifest_x* manifest) { strdup((context_->root_application_path.get() / manifest->package / "bin" / application->appid).c_str()); application->type = strdup("webapp"); - application->nodisplay = strdup("false"); + application->nodisplay = strdup("true"); application->taskmanage = strdup("false"); SetApplicationXDefaults(application); application->ambient_support = strdup("false"); -- 2.34.1 From f3af9bd52c8664b63d301a4c62e1d45e5bd3d063 Mon Sep 17 00:00:00 2001 From: Piotr Ganicz Date: Tue, 28 Jun 2016 12:52:34 +0200 Subject: [PATCH 12/16] [Refactor] check-coding-style Change-Id: If44523674d80b403d32af34848230f53a2620d0b --- src/wgt/step/pkgmgr/step_generate_xml.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wgt/step/pkgmgr/step_generate_xml.cc b/src/wgt/step/pkgmgr/step_generate_xml.cc index 8e92818..dffb4c8 100644 --- a/src/wgt/step/pkgmgr/step_generate_xml.cc +++ b/src/wgt/step/pkgmgr/step_generate_xml.cc @@ -119,7 +119,8 @@ bool WriteWidgetApplicationAttributesAndElements( std::string type = wgt::parse::AppWidgetSizeTypeToString(size.type); if (!size.preview.empty()) { - std::string icon_name = shared_path.string() + "/" + appwidget->id + "." + type + "." + "preview" + + std::string icon_name = shared_path.string() + "/" + + appwidget->id + "." + type + "." + "preview" + bf::path(size.preview).extension().string(); xmlTextWriterWriteAttribute(writer, BAD_CAST "preview", BAD_CAST icon_name.c_str()); // NOLINT -- 2.34.1 From 5957350d379b2307e5b2d33ce2ce90137fe536a0 Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Fri, 1 Jul 2016 11:01:36 +0200 Subject: [PATCH 13/16] Check if widget's shared/res/ entry is directory Installation will succeed if shared/res entry is not directory. Change-Id: I06e2b3934dd1342ad7ae98fd681a4b2a21d13885 --- src/wgt/step/filesystem/step_wgt_patch_storage_directories.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/wgt/step/filesystem/step_wgt_patch_storage_directories.cc b/src/wgt/step/filesystem/step_wgt_patch_storage_directories.cc index 3c5d9e9..fbb8519 100644 --- a/src/wgt/step/filesystem/step_wgt_patch_storage_directories.cc +++ b/src/wgt/step/filesystem/step_wgt_patch_storage_directories.cc @@ -52,6 +52,10 @@ bool StepWgtPatchStorageDirectories::ShareDirFor3x() { bf::path src = context_->pkg_path.get() / kResWgtSubPath / kSharedResLocation; if (!bf::exists(src)) return true; + if (!bf::is_directory(src)) { + LOG(WARNING) << "Widget's shared/res/ is not directory"; + return true; + } bf::path dst = context_->pkg_path.get() / kSharedResLocation; if (!common_installer::MoveDir(src, dst, common_installer::FS_MERGE_DIRECTORIES)) { -- 2.34.1 From 5f8f5211a72c991d466192146ce0bbfba45ef22c Mon Sep 17 00:00:00 2001 From: JongHeon Choi Date: Tue, 5 Jul 2016 14:29:55 +0900 Subject: [PATCH 14/16] Fixed app_keys name.(kAccountKey -> kTizenImeKey) Change-Id: Ifba625f6d0513499fed01360f63cacfc64b9d86d --- src/wgt/step/configuration/step_parse.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wgt/step/configuration/step_parse.cc b/src/wgt/step/configuration/step_parse.cc index df06790..0295903 100644 --- a/src/wgt/step/configuration/step_parse.cc +++ b/src/wgt/step/configuration/step_parse.cc @@ -537,7 +537,7 @@ bool StepParse::FillAccounts(manifest_x* manifest) { bool StepParse::FillImeInfo() { auto ime_info = GetManifestDataForKey( - app_keys::kAccountKey); + app_keys::kTizenImeKey); if (!ime_info) return true; -- 2.34.1 From 3014326fcc25ea087930aa64b855dbfb9eabf785 Mon Sep 17 00:00:00 2001 From: Inhwan Lee Date: Thu, 16 Jun 2016 19:14:55 +0900 Subject: [PATCH 15/16] implement step for use user extension Change-Id: Ie5442f543f6e4dc3dbf78685716db2b113c021d0 --- src/wgt/CMakeLists.txt | 2 + src/wgt/extension_config_parser.cc | 190 ++++++++++++++++++ src/wgt/extension_config_parser.h | 36 ++++ .../step_check_extension_privileges.cc | 132 ++++++++++++ .../step_check_extension_privileges.h | 55 +++++ src/wgt/wgt_installer.cc | 7 + 6 files changed, 422 insertions(+) mode change 100644 => 100755 src/wgt/CMakeLists.txt create mode 100755 src/wgt/extension_config_parser.cc create mode 100755 src/wgt/extension_config_parser.h create mode 100755 src/wgt/step/security/step_check_extension_privileges.cc create mode 100755 src/wgt/step/security/step_check_extension_privileges.h mode change 100644 => 100755 src/wgt/wgt_installer.cc diff --git a/src/wgt/CMakeLists.txt b/src/wgt/CMakeLists.txt old mode 100644 new mode 100755 index f45acc5..2e70267 --- a/src/wgt/CMakeLists.txt +++ b/src/wgt/CMakeLists.txt @@ -18,8 +18,10 @@ SET(SRCS step/security/step_check_wgt_notification_category.cc step/security/step_check_wgt_ime_privilege.cc step/security/step_direct_manifest_check_signature.cc + step/security/step_check_extension_privileges.cc wgt_app_query_interface.cc wgt_installer.cc + extension_config_parser.cc ) IF(WRT_LAUNCHER) diff --git a/src/wgt/extension_config_parser.cc b/src/wgt/extension_config_parser.cc new file mode 100755 index 0000000..4813d72 --- /dev/null +++ b/src/wgt/extension_config_parser.cc @@ -0,0 +1,190 @@ +// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by a apache 2.0 license that can be +// found in the LICENSE file. + +#include "wgt/extension_config_parser.h" +#include +#include + +#include +#include + +namespace wgt { + +namespace { +const xmlChar kExtensionNodeKey[] = "extension"; +const xmlChar kNamePrivilegeKey[] = "privilege"; +const xmlChar kPrivigeNameAttributeKey[] = "name"; +const char kAttributePrefix[] = "@"; +const xmlChar kDirAttributeKey[] = "dir"; +const char kXmlTextKey[] = "#text"; +const char kNamespaceKey[] = "@namespace"; +const char kExtensionPath[] = "extension.privilege"; +const char kExtensionNameKey[] = "@name"; +} // namespace + +ExtensionConfigParser::ExtensionConfigParser(std::string config_xml) { + config_xml_ = config_xml; +} + +std::unique_ptr + ExtensionConfigParser::LoadExtensionConfig(const std::string& config_xml) { + xmlDoc *doc = nullptr; + xmlNode* root_node = nullptr; + doc = xmlReadFile(config_xml.c_str(), nullptr, XML_PARSE_NOENT); + if (!doc) { + LOG(ERROR) << "Failed to read xml document model from" << config_xml; + return nullptr; + } + root_node = xmlDocGetRootElement(doc); + std::unique_ptr dv = LoadXMLNode(root_node); + std::unique_ptr result(new parser::DictionaryValue); + if (dv) + result->Set(reinterpret_cast(root_node->name), dv.release()); + return result; +} + +std::string ExtensionConfigParser::GetNodeDir( + xmlNode* node, const std::string& inherit_dir) { + std::string dir(inherit_dir); + for (xmlAttr* prop = node->properties; prop; prop = prop->next) { + if (xmlStrEqual(prop->name, kDirAttributeKey)) { + char* prop_value = reinterpret_cast(xmlNodeListGetString( + node->doc, prop->children, 1)); + dir = prop_value; + xmlFree(prop_value); + break; + } + } + return dir; +} +std::string ExtensionConfigParser::GetNodeText( + xmlNode* root, const std::string& inherit_dir) { + if (root->type != XML_ELEMENT_NODE) + return std::string(); + std::string current_dir(GetNodeDir(root, inherit_dir)); + std::string text; + if (!current_dir.empty()) + text += parser::utils::GetDirUTF8Start(current_dir); + for (xmlNode* node = root->children; node; node = node->next) { + if (node->type == XML_TEXT_NODE || node->type == XML_CDATA_SECTION_NODE) + text = text + std::string(reinterpret_cast(node->content)); + else + text += GetNodeText(node, current_dir); + } + if (!current_dir.empty()) + text += parser::utils::GetDirUTF8End(); + return text; +} +bool ExtensionConfigParser::IsPropSupportDir(xmlNode* root, xmlAttr* prop) { + if (xmlStrEqual(root->name, kNamePrivilegeKey) + && xmlStrEqual(prop->name, kPrivigeNameAttributeKey)) { + return true; + } + return false; +} +bool ExtensionConfigParser::IsTrimRequiredForElement(xmlNode* root) { + if (xmlStrEqual(root->name, kNamePrivilegeKey)) { + return true; + } + return false; +} +bool ExtensionConfigParser::IsTrimRequiredForProp( + xmlNode* root, xmlAttr* prop) { + if (xmlStrEqual(root->name, kNamePrivilegeKey) && + xmlStrEqual(prop->name, kPrivigeNameAttributeKey)) { + return true; + } + return false; +} +std::unique_ptr + ExtensionConfigParser::LoadXMLNode( + xmlNode* root, const std::string& inherit_dir) { + std::unique_ptr value(new parser::DictionaryValue()); + if (root->type != XML_ELEMENT_NODE) + return nullptr; + + std::string current_dir(GetNodeDir(root, inherit_dir)); + + xmlAttr* prop = nullptr; + for (prop = root->properties; prop; prop = prop->next) { + xmlChar* value_ptr = xmlNodeListGetString(root->doc, prop->children, 1); + std::string prop_value(reinterpret_cast(value_ptr)); + xmlFree(value_ptr); + if (IsPropSupportDir(root, prop)) + prop_value = parser::utils::GetDirTextUTF8(prop_value, current_dir); + + if (IsTrimRequiredForProp(root, prop)) + prop_value = parser::utils::CollapseWhitespaceUTF8(prop_value); + + value->SetString( + std::string(kAttributePrefix) + + reinterpret_cast(prop->name), + prop_value); + } + + if (root->ns) + value->SetString(kNamespaceKey, + reinterpret_cast(root->ns->href)); + + for (xmlNode* node = root->children; node; node = node->next) { + std::string sub_node_name(reinterpret_cast(node->name)); + std::unique_ptr sub_value = + LoadXMLNode(node, current_dir); + + if (!sub_value) { + continue; + } + if (!value->HasKey(sub_node_name)) { + value->Set(sub_node_name, sub_value.release()); + continue; + } + + parser::Value* temp; + value->Get(sub_node_name, &temp); + + if (temp->IsType(parser::Value::TYPE_LIST)) { + parser::ListValue* list; + temp->GetAsList(&list); + list->Append(sub_value.release()); + } else { + assert(temp->IsType(parser::Value::TYPE_DICTIONARY)); + parser::DictionaryValue* dict; + temp->GetAsDictionary(&dict); + parser::DictionaryValue* prev_value = dict->DeepCopy(); + + parser::ListValue* list = new parser::ListValue(); + list->Append(prev_value); + list->Append(sub_value.release()); + value->Set(sub_node_name, list); + } + } + + std::string text; + xmlChar* text_ptr = xmlNodeListGetString(root->doc, root->children, 1); + if (text_ptr) { + text = reinterpret_cast(text_ptr); + xmlFree(text_ptr); + } + if (IsTrimRequiredForElement(root)) + text = parser::utils::CollapseWhitespaceUTF8(text); + if (!text.empty()) + value->SetString(kXmlTextKey, text); + + return value; +} +std::vector ExtensionConfigParser::GetExtensionPrivilegeList() { + std::unique_ptr dic + = LoadExtensionConfig(config_xml_); + std::vector privilege_list; + + for (auto& item : parser::GetOneOrMany(dic.get(), kExtensionPath, "")) { + std::string privilege; + if (item->GetString(kExtensionNameKey, &privilege)) { + LOG(DEBUG) << "User defined extra privilege: " << privilege; + privilege_list.push_back(privilege); + } + } + return privilege_list; +} +} // namespace wgt diff --git a/src/wgt/extension_config_parser.h b/src/wgt/extension_config_parser.h new file mode 100755 index 0000000..c5cd454 --- /dev/null +++ b/src/wgt/extension_config_parser.h @@ -0,0 +1,36 @@ +// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by a apache 2.0 license that can be +// found in the LICENSE file. + +#ifndef WGT_EXTENSION_CONFIG_PARSER_H_ +#define WGT_EXTENSION_CONFIG_PARSER_H_ + +#include +#include +#include +#include + +#include +#include +#include + +namespace wgt { +class ExtensionConfigParser { + public: + explicit ExtensionConfigParser(std::string config_xml); + std::vector GetExtensionPrivilegeList(); + private: + std::unique_ptr LoadExtensionConfig( + const std::string& config_xml); + std::string GetNodeDir(xmlNode* node, const std::string& inherit_dir); + std::string GetNodeText(xmlNode* root, const std::string& inherit_dir); + bool IsPropSupportDir(xmlNode* root, xmlAttr* prop); + bool IsTrimRequiredForElement(xmlNode* root); + bool IsTrimRequiredForProp(xmlNode* root, xmlAttr* prop); + std::unique_ptr LoadXMLNode( + xmlNode* root, const std::string& inherit_dir = ""); + std::string config_xml_; +}; +} // namespace wgt + +#endif // WGT_EXTENSION_CONFIG_PARSER_H_ diff --git a/src/wgt/step/security/step_check_extension_privileges.cc b/src/wgt/step/security/step_check_extension_privileges.cc new file mode 100755 index 0000000..f75c832 --- /dev/null +++ b/src/wgt/step/security/step_check_extension_privileges.cc @@ -0,0 +1,132 @@ +// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by a apache 2.0 license that can be +// found in the LICENSE file. + +#include "wgt/step/security/step_check_extension_privileges.h" +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "wgt/extension_config_parser.h" +#include "manifest_parser/values.h" +#include "common/certificate_validation.h" +#include "common/utils/glist_range.h" + +namespace { +const char kPluginsDirectory[] = "/res/wgt/plugin/"; +const char kArchArmv7l[] = "armv7l"; +const char kArchI586[] = "i586"; +const char kArchDefault[] = "default"; +} + +namespace wgt { +namespace security { + +common_installer::Step::Status StepCheckExtensionPrivileges::precheck() { + if (!context_->manifest_data.get()) { + LOG(ERROR) << "Manifest data is not set"; + return Status::ERROR; + } + return Status::OK; +} +common_installer::Step::Status StepCheckExtensionPrivileges::process() { + std::string app_ext_config_pattern(GetExtensionPath()); + + manifest_x* m = context_->manifest_data.get(); + std::set current_privileges; + for (const char* priv : GListRange(m->privileges)) { + current_privileges.insert(priv); + } + + std::set xmlFiles; + { + glob_t glob_result; + glob(app_ext_config_pattern.c_str(), GLOB_TILDE, NULL, &glob_result); + for (unsigned int i = 0; i < glob_result.gl_pathc; ++i) { + xmlFiles.insert(glob_result.gl_pathv[i]); + } + } + std::set privileges; + for (auto it = xmlFiles.begin(); it != xmlFiles.end(); ++it) { + LOG(DEBUG) << "start to parse extension xml : " << *it; + ExtensionConfigParser extensionParser(*it); + std::vector list = extensionParser.GetExtensionPrivilegeList(); + for (int i = 0 ; i < list.size() ; i++) { + if (current_privileges.find(list[i]) == current_privileges.end()) { + privileges.insert(list[i]); + } + } + } + + if (!privileges.empty()) { + if (!CheckPriviligeLevel(privileges)) { + LOG(DEBUG) << "Fail to validation of privilege"; + return Status::ERROR; + } + for (auto it = privileges.begin(); it != privileges.end(); ++it) { + LOG(DEBUG) << "set list privilege : " << *it; + m->privileges = g_list_append(m->privileges, strdup((*it).c_str())); + } + } + return Status::OK; +} + +std::string StepCheckExtensionPrivileges::GetExtensionPath() { + std::string app_ext_config_pattern(context_->pkg_path.get().string()); + app_ext_config_pattern.append(kPluginsDirectory); + struct utsname u; + if (0 == uname(&u)) { + std::string machine = u.machine; + LOG(DEBUG) << "Machine archicture for user defined plugins: " << machine; + if (!machine.empty()) { + if (machine == kArchArmv7l) { + app_ext_config_pattern.append(kArchArmv7l); + } else if (machine == kArchI586) { + app_ext_config_pattern.append(kArchI586); + } else { + app_ext_config_pattern.append(kArchDefault); + } + } else { + LOG(ERROR) << "cannot get machine info"; + app_ext_config_pattern.append(kArchDefault); + } + app_ext_config_pattern.append("/"); + } + app_ext_config_pattern.append("*"); + app_ext_config_pattern.append(".xml"); + return app_ext_config_pattern; +} + +bool StepCheckExtensionPrivileges::CheckPriviligeLevel( + std::set priv_set) { + GList* privileges = nullptr; + for (auto it = priv_set.begin(); it != priv_set.end(); ++it) { + privileges = g_list_append(privileges, strdup((*it).c_str())); + } + guint size = g_list_length(privileges); + if (size == 0) return true; + + std::string error_message; + if (!common_installer::ValidatePrivilegeLevel( + context_->privilege_level.get(), + false, + context_->manifest_data.get()->api_version, + privileges, + &error_message)) { + if (!error_message.empty()) { + LOG(ERROR) << "error_message: " << error_message; + return false; + } + return false; + } + return true; +} + +} // namespace security +} // namespace wgt diff --git a/src/wgt/step/security/step_check_extension_privileges.h b/src/wgt/step/security/step_check_extension_privileges.h new file mode 100755 index 0000000..0c27abc --- /dev/null +++ b/src/wgt/step/security/step_check_extension_privileges.h @@ -0,0 +1,55 @@ +// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by a apache 2.0 license that can be +// found in the LICENSE file. +// Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved +// Use of this source code is governed by a apache 2.0 license that can be +// found in the LICENSE file. + +#ifndef WGT_STEP_SECURITY_STEP_CHECK_EXTENSION_PRIVILEGES_H_ +#define WGT_STEP_SECURITY_STEP_CHECK_EXTENSION_PRIVILEGES_H_ + +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace wgt { +namespace security { + +/** + * \brief Step that add user extension privileges during installation + */ +class StepCheckExtensionPrivileges : public common_installer::Step { + public: + using Step::Step; + + /** + * \Adds extra package privileges defined by extension manifest. + * + * \return Status::OK + */ + Status process() override; + Status clean() override { return Status::OK; } + Status undo() override { return Status::OK; } + /** + * \brief Check requirements for this step + * + * \return Status::ERROR when rmanifest data are missing, + * Status::OK otherwise + */ + Status precheck() override; + private: + std::string GetExtensionPath(); + bool CheckPriviligeLevel(std::set priv_set); + STEP_NAME(CheckExtensionPrivileges) +}; + +} // namespace security +} // namespace wgt + +#endif // WGT_STEP_SECURITY_STEP_CHECK_EXTENSION_PRIVILEGES_H_ diff --git a/src/wgt/wgt_installer.cc b/src/wgt/wgt_installer.cc old mode 100644 new mode 100755 index 7abd4e2..ee5f62c --- a/src/wgt/wgt_installer.cc +++ b/src/wgt/wgt_installer.cc @@ -82,6 +82,7 @@ #include "wgt/step/security/step_check_wgt_notification_category.h" #include "wgt/step/security/step_check_wgt_ime_privilege.h" #include "wgt/step/security/step_direct_manifest_check_signature.h" +#include "wgt/step/security/step_check_extension_privileges.h" namespace ci = common_installer; @@ -118,6 +119,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); + AddStep(); AddStep(); AddStep(); AddStep( @@ -157,6 +159,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); + AddStep(); AddStep(); AddStep(); AddStep( @@ -202,6 +205,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); + AddStep(); AddStep(); break; } @@ -241,6 +245,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); + AddStep(); AddStep(); AddStep(); AddStep( @@ -301,6 +306,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep( ci::Plugin::ActionType::Install); AddStep(); + AddStep(); AddStep(); break; } @@ -332,6 +338,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr) AddStep(); AddStep(); AddStep(); + AddStep(); AddStep(); AddStep(); AddStep( -- 2.34.1 From 8bdf473ae221b4ee3862fb6101b540fc9bdaf809 Mon Sep 17 00:00:00 2001 From: Piotr Ganicz Date: Mon, 11 Jul 2016 08:56:15 +0200 Subject: [PATCH 16/16] Fix memory leak in CheckPrivilegeLevel This patch fixes also typo in the function name. Change-Id: If118e0fd8d220e0d5dbb65a88b3a8f55a8cd343b --- src/wgt/step/security/step_check_extension_privileges.cc | 7 ++++--- src/wgt/step/security/step_check_extension_privileges.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/wgt/step/security/step_check_extension_privileges.cc b/src/wgt/step/security/step_check_extension_privileges.cc index f75c832..d2de923 100755 --- a/src/wgt/step/security/step_check_extension_privileges.cc +++ b/src/wgt/step/security/step_check_extension_privileges.cc @@ -65,7 +65,7 @@ common_installer::Step::Status StepCheckExtensionPrivileges::process() { } if (!privileges.empty()) { - if (!CheckPriviligeLevel(privileges)) { + if (!CheckPrivilegeLevel(privileges)) { LOG(DEBUG) << "Fail to validation of privilege"; return Status::ERROR; } @@ -103,7 +103,7 @@ std::string StepCheckExtensionPrivileges::GetExtensionPath() { return app_ext_config_pattern; } -bool StepCheckExtensionPrivileges::CheckPriviligeLevel( +bool StepCheckExtensionPrivileges::CheckPrivilegeLevel( std::set priv_set) { GList* privileges = nullptr; for (auto it = priv_set.begin(); it != priv_set.end(); ++it) { @@ -119,12 +119,13 @@ bool StepCheckExtensionPrivileges::CheckPriviligeLevel( context_->manifest_data.get()->api_version, privileges, &error_message)) { + g_list_free_full(privileges, free); if (!error_message.empty()) { LOG(ERROR) << "error_message: " << error_message; - return false; } return false; } + g_list_free_full(privileges, free); return true; } diff --git a/src/wgt/step/security/step_check_extension_privileges.h b/src/wgt/step/security/step_check_extension_privileges.h index 0c27abc..837f564 100755 --- a/src/wgt/step/security/step_check_extension_privileges.h +++ b/src/wgt/step/security/step_check_extension_privileges.h @@ -45,7 +45,7 @@ class StepCheckExtensionPrivileges : public common_installer::Step { Status precheck() override; private: std::string GetExtensionPath(); - bool CheckPriviligeLevel(std::set priv_set); + bool CheckPrivilegeLevel(std::set priv_set); STEP_NAME(CheckExtensionPrivileges) }; -- 2.34.1