SET(DECLARE_POPUP_USER "")
SET(DECLARE_POPUP_GROUP "")
SET(DECLARE_POPUP_SMACK_PROCESS_LABEL "")
+
+ ADD_DEFINITIONS("-DTZ_SYS_STORAGE=\"${TZ_SYS_STORAGE}\"")
+ ADD_DEFINITIONS("-DTZ_SYS_RW_APP=\"${TZ_SYS_RW_APP}\"")
+ ADD_DEFINITIONS("-DTZ_SYS_RO_APP=\"${TZ_SYS_RO_APP}\"")
+
CONFIGURE_FILE(packaging/${SERVICE_NAME}.manifest.in ${SERVICE_NAME}.manifest @ONLY)
CONFIGURE_FILE(packaging/${SERVICE_NAME}-test.manifest.in ${SERVICE_NAME}-test.manifest @ONLY)
CONFIGURE_FILE(data/scripts/${SERVICE_NAME}-upgrade.sh.in data/scripts/${SERVICE_NAME}-upgrade.sh @ONLY)
BuildRequires: pkgconfig(efl-extension)
BuildRequires: pkgconfig(icu-i18n)
%if "%{?tizen_version}" == "3.0"
+BuildRequires: pkgconfig(libtzplatform-config)
BuildRequires: pkgconfig(cynara-client)
%else
BuildRequires: pkgconfig(libsmack)
BuildRequires: boost-devel
BuildRequires: pkgconfig(pkgmgr-info)
BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(storage)
Requires: %{name} = %{version}
%description test
-DWITH_SAMPLE_ENGINE:BOOL=OFF \
%endif
%if "%{?tizen_version}" == "3.0"
+ -DTZ_SYS_STORAGE=%TZ_SYS_STORAGE \
+ -DTZ_SYS_RW_APP=%TZ_SYS_RW_APP \
+ -DTZ_SYS_RO_APP=%TZ_SYS_RO_APP \
-DPLATFORM_VERSION_3:BOOL=ON
%else
-DPLATFORM_VERSION_3:BOOL=OFF
framework/service/fs-utils.cpp
framework/service/file-system.cpp
framework/service/app-deleter.cpp
+ framework/service/app-dirs.cpp
framework/service/iloader.cpp
framework/service/cs-loader.cpp
framework/service/wp-loader.cpp
*/
#include "service/server-service.h"
+#include "service/app-dirs.h"
#include "common/audit/logger.h"
int main(void)
try {
INFO("Start csr-server main!");
+ Csr::AppDirs::init();
+
Csr::ServerService service;
INFO("Let's start csr-server service!");
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+#include "service/app-dirs.h"
+
+#include <string>
+#include <mutex>
+
+namespace {
+
+inline std::regex _regex(const char *str)
+{
+ return std::regex(str, std::regex_constants::extended);
+}
+
+}
+
+namespace Csr {
+
+std::vector<std::regex> AppDirs::m_regex;
+
+const std::vector<std::regex> &AppDirs::get()
+{
+ return AppDirs::m_regex;
+}
+
+void AppDirs::init()
+{
+ static std::once_flag f;
+
+ std::call_once(f, []() { AppDirs::initOnce(); });
+}
+
+void AppDirs::initOnce()
+{
+#define __INS_REGEX(str) AppDirs::m_regex.emplace_back(_regex(str))
+
+#ifdef PLATFORM_VERSION_3
+ // internal storages
+ __INS_REGEX("^(" TZ_SYS_RW_APP "/([^/]+))"); // $TZ_SYS_RW_APP/{pkgid}/
+ __INS_REGEX("^(" TZ_SYS_RO_APP "/([^/]+))"); // $TZ_SYS_RO_APP/{pkgid}/
+ // (linked prefix)/home/{user}/(appdir)/{pkgid}/
+ __INS_REGEX("^(/home/([^/]+)/apps_rw/([^/]+))");
+ __INS_REGEX("^(/opt/usr/home/([^/]+)/apps_rw/([^/]+))");
+
+ // external storages
+ // (linked prefix)/sdcard/app2sd/{pkgid}/
+ // (linked prefix)/sdcard/app2sd/{user}/{pkgid}/
+ // (linked prefix)/sdcard/apps/{user}/apps_rw/{pkgid}/
+ __INS_REGEX("^(/sdcard/app2sd/([^/]+))");
+ __INS_REGEX("^(/sdcard/app2sd/([^/]+)/([^/]+))");
+ __INS_REGEX("^(/sdcard/apps/([^/]+)/apps_rw/([^/]+))");
+ __INS_REGEX("^(" TZ_SYS_STORAGE "/sdcard/app2sd/([^/]+))");
+ __INS_REGEX("^(" TZ_SYS_STORAGE "/sdcard/app2sd/([^/]+)/([^/]+))");
+ __INS_REGEX("^(" TZ_SYS_STORAGE "/sdcard/apps/([^/]+)/apps_rw/([^/]+))");
+#else
+ // internal storages
+ __INS_REGEX("^(/usr/apps/([^/]+))"); // /usr/apps/{pkgid}/
+ __INS_REGEX("^(/opt/usr/apps/([^/]+))"); // /opt/usr/apps/{pkgid}/
+
+ // external storages
+ __INS_REGEX("^(/sdcard/apps/([^/]+))"); // /sdcard/apps/{pkgid}/
+ __INS_REGEX("^(/sdcard/app2sd/([^/]+))"); // /sdcard/app2sd/{pkgid}/
+#endif
+
+#undef __INS_REGEX
+}
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+#pragma once
+
+#include <vector>
+#include <regex>
+
+namespace Csr {
+
+class AppDirs {
+public:
+ static const std::vector<std::regex> &get();
+ static void init();
+
+private:
+ static void initOnce();
+ static std::vector<std::regex> m_regex;
+};
+
+}
#include "common/audit/logger.h"
#include "common/exception.h"
#include "service/app-deleter.h"
+#include "service/app-dirs.h"
#include "service/fs-utils.h"
#include "service/dir-blacklist.h"
namespace Csr {
-namespace {
-
-inline std::regex makeRegexpr(const char *str)
-{
- return std::regex(str, std::regex_constants::extended);
-}
-
-std::vector<std::regex> g_regexprs{
-#ifdef PLATFORM_VERSION_3
- makeRegexpr("^(/opt/usr/apps/([^/]+))"), // /opt/usr/apps/{pkgid}/
- makeRegexpr("^(/home/([^/]+)/apps_rw/([^/]+))"), // /home/{user}/apps_rw/{pkgid}/
- makeRegexpr("^(/opt/home/([^/]+)/apps_rw/([^/]+))"), // /opt/home/{user}/apps_rw/{pkgid}/
- makeRegexpr("^(/sdcard/app2sd/([^/]+)/([^/]+))"), // /sdcard/app2sd/{user}/{pkgid}/
- makeRegexpr("^(/sdcard/app2sd/([^/]+))"), // /sdcard/app2sd/{pkgid}/
- makeRegexpr("^(/sdcard/apps/([^/]+)/apps_rw/([^/]+))") // /sdcard/apps/{user}/apps_rw/{pkgid}/
-#else
- makeRegexpr("^(/usr/apps/([^/]+))"), // /usr/apps/{pkgid}/
- makeRegexpr("^(/opt/usr/apps/([^/]+))"), // /opt/usr/apps/{pkgid}/
- makeRegexpr("^(/sdcard/apps/([^/]+))"), // /sdcard/apps/{pkgid}/
- makeRegexpr("^(/sdcard/app2sd/([^/]+))"), // /sdcard/app2sd/{pkgid}/
-#endif
-};
-
-} // namespace anonymous
-
int File::getPkgTypes(const std::string &user, const std::string &pkgid)
{
pkgmgrinfo_pkginfo_h handle;
{
std::smatch matched;
- for (const auto ®e : g_regexprs) {
+ for (const auto ®e : AppDirs::get()) {
if (!std::regex_search(path, matched, rege))
continue;
std::smatch matched;
- for (const auto ®e : g_regexprs) {
+ for (const auto ®e : AppDirs::get()) {
if (!std::regex_search(this->m_path, matched, rege))
continue;
glib-2.0
pkgmgr
pkgmgr-info
+ storage
)
SET(${TARGET_CSR_TEST_COMMON}_SRCS
${CSR_FW_SRC_PATH}/service/fs-utils.cpp
${CSR_FW_SRC_PATH}/service/file-system.cpp
${CSR_FW_SRC_PATH}/service/app-deleter.cpp
+ ${CSR_FW_SRC_PATH}/service/app-dirs.cpp
${CSR_FW_SRC_PATH}/service/iloader.cpp
${CSR_FW_SRC_PATH}/service/cs-loader.cpp
${CSR_FW_SRC_PATH}/service/wp-loader.cpp
Test::uninstall_app(TEST_WGT_PKG_ID);
Test::uninstall_app(TEST_TPK_PKG_ID);
- std::string homeDirPrefix;
-#ifdef PLATFORM_VERSION_3
- // "/home" is symlinked of "/opt/home" so in root directory scanning,
- // user directory prefix("/opt") is additionally needed to check file_name field
- // in malware handle
- homeDirPrefix = "/opt";
-#endif
-
ASSERT_DETECTED_IN_LIST(testCtx.detectedList, TEST_FILE_HIGH, MALWARE_HIGH_NAME,
MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_FILE_HIGH, false, "");
- ASSERT_DETECTED_IN_LIST(testCtx.detectedList, homeDirPrefix + TEST_FILE_MEDIA(),
+ ASSERT_DETECTED_IN_LIST(testCtx.detectedList, TEST_FILE_MEDIA(),
MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY,
MALWARE_HIGH_DETAILED_URL);
- ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, homeDirPrefix + TEST_FILE_MEDIA(),
- false, "");
+ ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_FILE_MEDIA(), false, "");
ASSERT_DETECTED_IN_LIST(testCtx.detectedList, TEST_FILE_TMP, MALWARE_HIGH_NAME,
MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_FILE_TMP, false, "");
- ASSERT_DETECTED_IN_LIST(testCtx.detectedList, homeDirPrefix + TEST_WGT_APP_ROOT(),
+ ASSERT_DETECTED_IN_LIST(testCtx.detectedList, TEST_WGT_APP_ROOT(),
MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY,
MALWARE_HIGH_DETAILED_URL);
- ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, homeDirPrefix + TEST_WGT_APP_ROOT(),
+ ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_WGT_APP_ROOT(),
true, TEST_WGT_PKG_ID);
- ASSERT_DETECTED_IN_LIST(testCtx.detectedList, homeDirPrefix + TEST_TPK_APP_ROOT(),
+ ASSERT_DETECTED_IN_LIST(testCtx.detectedList, TEST_TPK_APP_ROOT(),
MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY,
MALWARE_HIGH_DETAILED_URL);
- ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, homeDirPrefix + TEST_TPK_APP_ROOT(),
+ ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_TPK_APP_ROOT(),
true, TEST_TPK_PKG_ID);
- ASSERT_DETECTED_IN_LIST(testCtx.detectedList, homeDirPrefix + TEST_FAKE_APP_FILE(),
+ ASSERT_DETECTED_IN_LIST(testCtx.detectedList, TEST_FAKE_APP_FILE(),
MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY,
MALWARE_HIGH_DETAILED_URL);
- ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, homeDirPrefix + TEST_FAKE_APP_FILE(),
+ ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_FAKE_APP_FILE(),
false, "");
ASSERT_DETECTED_IN_LIST(testCtx.detectedList, TEST_FILE_MEDIUM, MALWARE_MEDIUM_NAME,
for (size_t i = 0; i < NUM; ++i)
ASSERT_CALLBACK(testCtxs[i], -1, -1, 1, 0, 0);
- std::string homeDirPrefix;
-#ifdef PLATFORM_VERSION_3
- // "/home" is symlinked of "/opt/home" so in root directory scanning,
- // user directory prefix("/opt") is additionally needed to check file_name field
- // in malware handle
- homeDirPrefix = "/opt";
-#endif
-
for (size_t i = 0; i < NUM; ++i) {
ASSERT_DETECTED_IN_LIST(testCtxs[i].detectedList, TEST_FILE_HIGH, MALWARE_HIGH_NAME,
MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
ASSERT_DETECTED_IN_LIST_EXT(testCtxs[i].detectedList, TEST_FILE_HIGH, false, "");
- ASSERT_DETECTED_IN_LIST(testCtxs[i].detectedList, homeDirPrefix + TEST_FILE_MEDIA(),
+ ASSERT_DETECTED_IN_LIST(testCtxs[i].detectedList, TEST_FILE_MEDIA(),
MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY,
MALWARE_HIGH_DETAILED_URL);
- ASSERT_DETECTED_IN_LIST_EXT(testCtxs[i].detectedList, homeDirPrefix + TEST_FILE_MEDIA(),
+ ASSERT_DETECTED_IN_LIST_EXT(testCtxs[i].detectedList, TEST_FILE_MEDIA(),
false, "");
ASSERT_DETECTED_IN_LIST(testCtxs[i].detectedList, TEST_FILE_TMP, MALWARE_HIGH_NAME,
MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL);
ASSERT_DETECTED_IN_LIST_EXT(testCtxs[i].detectedList, TEST_FILE_TMP, false, "");
- ASSERT_DETECTED_IN_LIST(testCtxs[i].detectedList, homeDirPrefix + TEST_WGT_APP_ROOT(),
+ ASSERT_DETECTED_IN_LIST(testCtxs[i].detectedList, TEST_WGT_APP_ROOT(),
MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY,
MALWARE_HIGH_DETAILED_URL);
- ASSERT_DETECTED_IN_LIST_EXT(testCtxs[i].detectedList, homeDirPrefix + TEST_WGT_APP_ROOT(),
+ ASSERT_DETECTED_IN_LIST_EXT(testCtxs[i].detectedList, TEST_WGT_APP_ROOT(),
true, TEST_WGT_PKG_ID);
- ASSERT_DETECTED_IN_LIST(testCtxs[i].detectedList, homeDirPrefix + TEST_TPK_APP_ROOT(),
+ ASSERT_DETECTED_IN_LIST(testCtxs[i].detectedList, TEST_TPK_APP_ROOT(),
MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY,
MALWARE_HIGH_DETAILED_URL);
- ASSERT_DETECTED_IN_LIST_EXT(testCtxs[i].detectedList, homeDirPrefix + TEST_TPK_APP_ROOT(),
+ ASSERT_DETECTED_IN_LIST_EXT(testCtxs[i].detectedList, TEST_TPK_APP_ROOT(),
true, TEST_TPK_PKG_ID);
- ASSERT_DETECTED_IN_LIST(testCtxs[i].detectedList, homeDirPrefix + TEST_FAKE_APP_FILE(),
+ ASSERT_DETECTED_IN_LIST(testCtxs[i].detectedList, TEST_FAKE_APP_FILE(),
MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY,
MALWARE_HIGH_DETAILED_URL);
- ASSERT_DETECTED_IN_LIST_EXT(testCtxs[i].detectedList, homeDirPrefix + TEST_FAKE_APP_FILE(),
+ ASSERT_DETECTED_IN_LIST_EXT(testCtxs[i].detectedList, TEST_FAKE_APP_FILE(),
false, "");
ASSERT_DETECTED_IN_LIST(testCtxs[i].detectedList, TEST_FILE_MEDIUM, MALWARE_MEDIUM_NAME,
#include "test-common.h"
+namespace {
+
+std::string get_real_filepath(const std::string &path)
+{
+ if (path.compare(0, strlen("/opt/usr/home"), "/opt/usr/home") == 0)
+ return path.substr(strlen("/opt/usr"));
+ else if (path.compare(0, strlen("/opt/media"), "/opt/media") == 0)
+ return path.substr(strlen("/opt"));
+ else
+ return path;
+}
+
+const char *get_real_filepath(const char *path)
+{
+ if (strncmp(path, "/opt/usr/home", strlen("/opt/usr/home")) == 0)
+ return path + strlen("/opt/usr");
+ else if (strncmp(path, "/opt/media", strlen("/opt/media")) == 0)
+ return path + strlen("/opt");
+ else
+ return path;
+}
+
+}
+
void ASSERT_DETECTED(csr_cs_malware_h detected, const std::string &e_malware_name,
csr_cs_severity_level_e e_severity, const std::string &e_detailed_url)
{
const std::string &file_name, const std::string &name,
csr_cs_severity_level_e severity, const std::string &detailed_url)
{
+ auto real_file_name = ::get_real_filepath(file_name);
csr_cs_severity_level_e a_severity;
Test::ScopedCstr a_file_name, a_name, a_detailed_url;
for (auto &d : detectedList) {
ASSERT_SUCCESS(csr_cs_malware_get_file_name(d, &a_file_name.ptr));
- if (file_name != a_file_name.ptr)
+ if (real_file_name.compare(::get_real_filepath(a_file_name.ptr)) != 0)
continue;
ASSERT_SUCCESS(csr_cs_malware_get_name(d, &a_name.ptr));
}
BOOST_REQUIRE_MESSAGE(false,
- "Cannot find the file[" << file_name << "] in detected list.");
+ "Cannot find the file[" << real_file_name << "] in detected list.");
}
void ASSERT_DETECTED_IN_LIST_EXT(const std::vector<csr_cs_malware_h> &detectedList,
const std::string &file_name, bool is_app,
const std::string &pkg_id)
{
+ auto real_file_name = ::get_real_filepath(file_name);
bool a_is_app;
Test::ScopedCstr a_file_name, a_pkg_id;
for (auto &d : detectedList) {
ASSERT_SUCCESS(csr_cs_malware_get_file_name(d, &a_file_name.ptr));
- if (file_name != a_file_name.ptr)
+ if (real_file_name.compare(::get_real_filepath(a_file_name.ptr)) != 0)
continue;
ASSERT_SUCCESS(csr_cs_malware_is_app(d, &a_is_app));
}
BOOST_REQUIRE_MESSAGE(false,
- "Cannot find the file[" << file_name << "] in detected list.");
+ "Cannot find the file[" << real_file_name << "] in detected list.");
}
#include <sys/types.h>
#include <pwd.h>
+#include <storage.h>
+
#include "test-common.h"
namespace {
const char *TEST_DIR_MEDIA(void)
{
- if (s_testDirMedia.empty())
-#ifdef PLATFORM_VERSION_3
- s_testDirMedia = "/home/" + ::getUsername() + "/content";
-#else
- s_testDirMedia = "/opt/usr/media";
-#endif
+ if (s_testDirMedia.empty()) {
+ char *path = nullptr;
+ if (storage_get_root_directory(STORAGE_TYPE_INTERNAL, &path) != STORAGE_ERROR_NONE)
+ throw std::logic_error("failed to storage_get_root_directory");
+
+ s_testDirMedia = path;
+ free(path);
+ }
return s_testDirMedia.c_str();
}