Don't check whether file is removable 12/73912/2
authorKyungwook Tak <k.tak@samsung.com>
Fri, 10 Jun 2016 04:47:09 +0000 (13:47 +0900)
committerKyungwook Tak <k.tak@samsung.com>
Fri, 10 Jun 2016 05:07:30 +0000 (14:07 +0900)
Client will get remove failed error code from csr_cs_judge_detected_malware
if the target is unremovable

Change-Id: Ic73ea49459afcc0407766a1d065dd92f262a3155
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
src/framework/service/cs-logic.cpp
src/framework/service/cs-logic.h
src/framework/service/file-system.cpp
src/framework/service/file-system.h

index f8ca02d..c8c55f6 100644 (file)
@@ -241,42 +241,23 @@ CsDetectedPtr CsLogic::scanAppDelta(const std::string &pkgPath, const std::strin
        return riskiest;
 }
 
-RawBuffer CsLogic::scanApp(const CsContext &context, const std::string &path)
+RawBuffer CsLogic::scanApp(const CsContext &context, const std::string &pkgPath)
 {
        FilePtr fileptr;
        try {
-               fileptr = File::create(path);
+               fileptr = File::create(pkgPath);
        } catch (const Exception &e) {
                if (e.error() == CSR_ERROR_FILE_DO_NOT_EXIST)
-                       WARN("Pinned file[" << path << " in app doesn't exist or perm denied.");
+                       WARN("Package path of file[" << pkgPath << "] doesn't exist or perm denied.");
                else if (e.error() == CSR_ERROR_FILE_SYSTEM)
-                       WARN("Pinned file[" << path << " in app type isn't regular file or dir.");
+                       WARN("Package path of file[" << pkgPath << "] type isn't regular file or dir.");
                else
                        throw;
        }
 
-       // try again to create FilePtr by package path
-       if (!fileptr) {
-               try {
-                       fileptr = File::create(File::getPkgPath(path));
-               } catch (const Exception &e) {
-                       if (e.error() == CSR_ERROR_FILE_DO_NOT_EXIST)
-                               WARN("Package path of file[" << path << "] doesn't exist or perm denied.");
-                       else if (e.error() == CSR_ERROR_FILE_SYSTEM)
-                               WARN("Package path of file[" << path << "] type isn't regular file or dir.");
-                       else
-                               throw;
-               }
-       }
-
        if (!fileptr->isInApp())
                ThrowExc(CSR_ERROR_SERVER, "fileptr should be in app.");
 
-       if (!fileptr->isRemovable())
-               ThrowExc(CSR_ERROR_PERMISSION_DENIED, "app[" << fileptr->getAppPkgPath() <<
-                                "] isn't removable.");
-
-       const auto &pkgPath = fileptr->getAppPkgPath();
        const auto &pkgId = fileptr->getAppPkgId();
 
        if (context.isScanOnCloud && this->m_loader->scanAppOnCloudSupported())
@@ -407,6 +388,8 @@ RawBuffer CsLogic::scanFileWithoutDelta(const CsContext &context,
        if (result == nullptr)
                return BinaryQueue::Serialize(CSR_ERROR_NONE).pop();
 
+       INFO("New malware detected on file: " << filepath);
+
        auto d = this->convert(result, filepath, timestamp);
 
        this->m_db->insertName(d.targetName);
@@ -422,38 +405,40 @@ RawBuffer CsLogic::scanFile(const CsContext &context, const std::string &filepat
 
        setCoreUsage(context.coreUsage);
 
-       if (File::isInApp(filepath))
-               return this->scanApp(context, filepath);
+       auto target = canonicalizePath(filepath, true);
 
-       DEBUG("Scan request on file: " << filepath);
+       if (File::isInApp(target))
+               return this->scanApp(context, target);
 
-       auto history = this->m_db->getDetectedByNameOnPath(filepath);
+       DEBUG("Scan request on file: " << target);
+
+       auto history = this->m_db->getDetectedByNameOnPath(target);
 
        FilePtr fileptr;
 
        // if history exist, fileptr can be null because of modified since value
        // from history.
        if (history)
-               fileptr = File::createIfModified(filepath, static_cast<time_t>(history->ts));
+               fileptr = File::createIfModified(target, static_cast<time_t>(history->ts));
        else
-               fileptr = File::create(filepath);
+               fileptr = File::create(target);
 
        // non-null fileptr means the file is modified since the last history
        // OR there's no history at all.
        if (fileptr) {
                if (history)
-                       this->m_db->deleteDetectedByNameOnPath(filepath);
+                       this->m_db->deleteDetectedByNameOnPath(target);
 
                if (fileptr->isDir())
                        ThrowExc(CSR_ERROR_FILE_SYSTEM,
-                                        "file type shouldn't be directory: " << filepath);
+                                        "file type shouldn't be directory: " << target);
 
-               DEBUG("file[" << filepath << "] is modified since the detected time. "
+               DEBUG("file[" << target << "] is modified since the detected time. "
                          "let's remove history and re-scan");
-               return this->scanFileWithoutDelta(context, filepath, std::move(fileptr));
+               return this->scanFileWithoutDelta(context, target, std::move(fileptr));
        }
 
-       DEBUG("Usable scan history exist on file: " << filepath);
+       DEBUG("Usable scan history exist on file: " << target);
 
        if (history->isIgnored)
                return BinaryQueue::Serialize(CSR_ERROR_NONE).pop();
@@ -499,9 +484,6 @@ RawBuffer CsLogic::getScannableFiles(const std::string &dir)
        StrSet fileset;
 
        while (auto file = visitor->next()) {
-               if (!file->isRemovable())
-                       continue;
-
                if (file->isInApp()) {
                        DEBUG("Scannable app: " << file->getAppPkgPath());
                        fileset.insert(file->getAppPkgPath());
index ee1cea5..db6a258 100644 (file)
@@ -55,7 +55,7 @@ public:
        RawBuffer getIgnoredList(const StrSet &dirSet);
 
 private:
-       RawBuffer scanApp(const CsContext &context, const std::string &path);
+       RawBuffer scanApp(const CsContext &context, const std::string &pkgPath);
        RawBuffer scanAppOnCloud(const CsContext &context, const std::string &pkgPath,
                                                         const std::string &pkgId);
        CsDetectedPtr scanAppDelta(const std::string &pkgPath, const std::string &pkgId,
index 29be70e..2c37315 100644 (file)
@@ -59,12 +59,6 @@ std::vector<std::regex> g_regexprs{
 #endif
 };
 
-bool hasPermToRemove(const std::string &filepath)
-{
-       auto parent = filepath.substr(0, filepath.find_last_of('/'));
-       return ::access(parent.c_str(), W_OK) == 0;
-}
-
 } // namespace anonymous
 
 int File::getPkgTypes(const std::string &pkgid)
@@ -76,18 +70,8 @@ int File::getPkgTypes(const std::string &pkgid)
 
        auto type = static_cast<int>(Type::Package);
 
-       bool isRemovable = false;
-       ret = ::pkgmgrinfo_pkginfo_is_removable(handle, &isRemovable);
-       if (ret != PMINFO_R_OK) {
-               ERROR("Failed to pkgmgrinfo_pkginfo_is_removable. ret: " << ret);
-               return type;
-       }
-
        ::pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
 
-       if (isRemovable)
-               type |= static_cast<int>(Type::Removable);
-
        return type;
 }
 
@@ -189,11 +173,6 @@ bool File::isDir() const noexcept
        return this->m_type & static_cast<int>(Type::Directory);
 }
 
-bool File::isRemovable() const noexcept
-{
-       return this->m_type & static_cast<int>(Type::Removable);
-}
-
 bool File::isModified() const noexcept
 {
        return this->m_type & static_cast<int>(Type::Modified);
@@ -249,9 +228,6 @@ FilePtr File::createInternal(const std::string &fpath, time_t modifiedSince,
 
        auto type = static_cast<int>(S_ISREG(statptr->st_mode) ? Type::File : Type::Directory);
 
-       if (hasPermToRemove(fpath))
-               type |= static_cast<int>(Type::Removable);
-
        if (modifiedSince == -1 || statptr->st_ctime > modifiedSince) {
                DEBUG("file[" << fpath << "] is changed since[" << modifiedSince << "]");
                type |= static_cast<int>(Type::Modified);
index 3b140b8..88e8c1a 100644 (file)
@@ -41,7 +41,6 @@ public:
        const std::string &getPath() const noexcept;
        bool isInApp() const noexcept;
        bool isDir() const noexcept;
-       bool isRemovable() const noexcept;
        bool isModified() const noexcept;
        const std::string &getAppPkgId() const noexcept;
        const std::string &getAppUser() const noexcept;
@@ -59,10 +58,9 @@ public:
 private:
        enum class Type : int {
                Modified  = (1 << 0),
-               Removable = (1 << 1),
-               Package   = (1 << 2),
-               File      = (1 << 3),
-               Directory = (1 << 4),
+               Package   = (1 << 1),
+               File      = (1 << 2),
+               Directory = (1 << 3),
        };
 
        static FilePtr createInternal(const std::string &fpath, time_t modifiedSince,