summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyungwook Tak <k.tak@samsung.com>2016-12-29 19:44:13 +0900
committerkyungwook tak <k.tak@samsung.com>2016-12-29 03:11:57 -0800
commit8756a58db5971eec1864c27da179966aa8050b76 (patch)
tree8e85146487bdacc5adbf99c6052dbb8b933f1f0a
parent62913b6fc41ef691715c32cd2ceb412e397569a3 (diff)
downloadcsr-framework-8756a58db5971eec1864c27da179966aa8050b76.tar.gz
csr-framework-8756a58db5971eec1864c27da179966aa8050b76.tar.bz2
csr-framework-8756a58db5971eec1864c27da179966aa8050b76.zip
Handle symbolic links in app directory
App directory hierarchy is changed. Non global apps have symbolic link which points under TZ_SYS_RW_APPS(/opt/usr/globalapps/...) because non global app's binary and resources are duplicated if such app installed by multiple users. So FsVisitor traverses through symlink either only in app directory which is defined in AppDir class in regular expression. Change-Id: I3049fcb92258fc8d8b4123d74856a4d584ebcdfe Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
-rw-r--r--src/framework/service/file-system.cpp97
-rw-r--r--src/framework/service/file-system.h2
-rw-r--r--test/engine/content-screening/sample-engine.cpp24
3 files changed, 79 insertions, 44 deletions
diff --git a/src/framework/service/file-system.cpp b/src/framework/service/file-system.cpp
index 2422a4d..8458052 100644
--- a/src/framework/service/file-system.cpp
+++ b/src/framework/service/file-system.cpp
@@ -301,54 +301,73 @@ void FsVisitor::run(const DirPtr &dirptr, const FilePtr &currentdir)
auto fullpath = (parent_dirpath.back() == '/') ?
(parent_dirpath + name) : (parent_dirpath + "/" + name);
- if (result->d_type == DT_DIR) {
+ INFO("start to traverse file: " << fullpath);
+
+ if (result->d_type == DT_LNK) {
+ if (!currentdir->isInApp())
+ continue;
+
+ auto stat = getStat(fullpath);
+ if (S_ISREG(stat->st_mode))
+ this->visitFile(fullpath, currentdir);
+ else if (S_ISDIR(stat->st_mode))
+ this->visitDir(fullpath, currentdir);
+
+ } else if (result->d_type == DT_DIR) {
if ((name_size == 1 && name[0] == '.') ||
(name_size == 2 && name[0] == '.' && name[1] == '.'))
continue;
- FilePtr ncurrentdir;
- try {
- ncurrentdir = File::create(fullpath, currentdir);
- } catch (const Exception &e) {
- if (e.error() == CSR_ERROR_FILE_DO_NOT_EXIST) {
- WARN("Perm denied to create file on pkg path: " << fullpath);
- continue;
- } else {
- throw;
- }
- }
-
- if (this->m_isBasedOnName && ncurrentdir->isInApp()) {
- this->m_targetHandler(ncurrentdir);
- } else {
- auto ndirptr = openDir(fullpath);
- if (ndirptr == nullptr) {
- WARN("Failed to open dir: " << fullpath << " with errno: " << errno);
- continue;
- }
-
- DEBUG("recurse dir : " << fullpath);
- this->run(ndirptr, ncurrentdir);
- }
+ this->visitDir(fullpath, currentdir);
} else if (result->d_type == DT_REG) {
- try {
- auto fileptr = File::createIfModified(fullpath, currentdir, this->m_since);
-
- if (fileptr)
- this->m_targetHandler(fileptr);
- } catch (const Exception &e) {
- if (e.error() == CSR_ERROR_FILE_DO_NOT_EXIST)
- WARN("file not exist: " << fullpath << " msg: " << e.what());
- else if (e.error() == CSR_ERROR_FILE_SYSTEM)
- WARN("file type is not regular...? can it be happened?"
- " :" << fullpath << " msg: " << e.what());
- else
- throw;
- }
+ this->visitFile(fullpath, currentdir);
}
}
}
+void FsVisitor::visitDir(const std::string &fullpath, const FilePtr &currentdir)
+{
+ FilePtr ncurrentdir;
+
+ try {
+ ncurrentdir = File::create(fullpath, currentdir);
+ } catch (const Exception &e) {
+ if (e.error() == CSR_ERROR_FILE_DO_NOT_EXIST) {
+ WARN("Perm denied to create file on pkg path: " << fullpath);
+ return;
+ } else {
+ throw;
+ }
+ }
+
+ if (this->m_isBasedOnName && ncurrentdir->isInApp()) {
+ this->m_targetHandler(ncurrentdir);
+ } else {
+ if (auto ndirptr = openDir(fullpath)) {
+ DEBUG("recurse dir: " << fullpath);
+ this->run(ndirptr, ncurrentdir);
+ } else {
+ WARN("Failed to open dir: " << fullpath << " with errno: " << errno);
+ }
+ }
+}
+
+void FsVisitor::visitFile(const std::string &fullpath, const FilePtr &currentdir)
+{
+ try {
+ if (auto fileptr = File::createIfModified(fullpath, currentdir, this->m_since))
+ this->m_targetHandler(fileptr);
+ } catch (const Exception &e) {
+ if (e.error() == CSR_ERROR_FILE_DO_NOT_EXIST)
+ WARN("file not exist: " << fullpath << " msg: " << e.what());
+ else if (e.error() == CSR_ERROR_FILE_SYSTEM)
+ WARN("file type is not regular...? can it be happened?"
+ " :" << fullpath << " msg: " << e.what());
+ else
+ throw;
+ }
+}
+
void FsVisitor::run()
{
auto currentdir = File::create(this->m_path, nullptr);
diff --git a/src/framework/service/file-system.h b/src/framework/service/file-system.h
index ee73279..7166c47 100644
--- a/src/framework/service/file-system.h
+++ b/src/framework/service/file-system.h
@@ -170,6 +170,8 @@ private:
using DirPtr = std::unique_ptr<Dir>;
void run(const DirPtr &dirptr, const FilePtr &currentdir);
+ void visitDir(const std::string &fullpath, const FilePtr &currentdir);
+ void visitFile(const std::string &fullpath, const FilePtr &currentdir);
static DirPtr openDir(const std::string &);
diff --git a/test/engine/content-screening/sample-engine.cpp b/test/engine/content-screening/sample-engine.cpp
index 34afff7..29634e8 100644
--- a/test/engine/content-screening/sample-engine.cpp
+++ b/test/engine/content-screening/sample-engine.cpp
@@ -477,14 +477,28 @@ int csre_cs_scan_app_on_cloud(csre_cs_context_h handle,
int ret = CSRE_ERROR_NONE;
- if (result->d_type & (DT_REG | DT_LNK))
+ if (result->d_type == DT_LNK) {
+ // when the file type is link, check the real file's type(dir or reg file)
+ // and go ahead to traverse
+ struct stat s;
+ if (stat(fullpath.c_str(), &s) != 0)
+ continue; // failed to get stat
+
+ if (S_ISREG(s.st_mode))
+ ret = csre_cs_scan_file(handle, fullpath.c_str(), &detected);
+ else if (S_ISDIR(s.st_mode))
+ ret = csre_cs_scan_app_on_cloud(handle, fullpath.c_str(), &detected);
+ else
+ continue;
+ } else if (result->d_type == DT_REG) {
ret = csre_cs_scan_file(handle, fullpath.c_str(), &detected);
- else if ((result->d_type & DT_DIR)
- && filename.compare("..") != 0
- && filename.compare(".") != 0)
+ } else if ((result->d_type & DT_DIR) &&
+ filename.compare("..") != 0 &&
+ filename.compare(".") != 0) {
ret = csre_cs_scan_app_on_cloud(handle, fullpath.c_str(), &detected);
- else
+ } else {
continue;
+ }
if (ret != CSRE_ERROR_NONE)
return ret;