#include <cerrno>
#include <unistd.h>
+#include <csr-error.h>
+
#include "common/audit/logger.h"
#include "common/exception.h"
#include "service/type-converter.h"
#include "service/core-usage.h"
#include "service/dir-blacklist.h"
+#include "service/fs-utils.h"
#include "ui/askuser.h"
-#include <csr-error.h>
namespace Csr {
auto resolved = resolvePath(path);
auto target = File::getPkgPath(resolved);
- if (checkAccess && ::access(target.c_str(), R_OK) != 0) {
+ if (checkAccess && !isReadable(path)) {
const int err = errno;
if (err == ENOENT)
ThrowExc(CSR_ERROR_FILE_DO_NOT_EXIST, "File do not exist: " << target);
Db::RowShPtrs rows;
for (const auto &dir : dirSet) {
for (auto &row : this->m_db->getDetectedByNameOnDir(dir)) {
- if (::access(row->targetName.c_str(), R_OK) != 0) {
+ if (!isReadable(row->targetName)) {
WARN("Exclude not-accessable malware detected file from the list: " <<
row->targetName);
this->m_db->deleteDetectedByNameOnPath(row->targetName);
Db::RowShPtrs rows;
for (const auto &dir : dirSet) {
for (auto &row : this->m_db->getDetectedByNameOnDir(dir)) {
- if (::access(row->targetName.c_str(), R_OK) != 0) {
+ if (!isReadable(row->targetName)) {
WARN("Exclude not-accessable malware detected file from the list: " <<
row->targetName);
this->m_db->deleteDetectedByNameOnPath(row->targetName);
namespace Csr {
+bool isReadable(const std::string &target)
+{
+ FILE *f = ::fopen(target.c_str(), "rb");
+
+ if (f == nullptr) {
+ return false;
+ } else {
+ ::fclose(f);
+ return true;
+ }
+}
+
uid_t getUid(const std::string &username)
{
auto bufsize = ::sysconf(_SC_GETPW_R_SIZE_MAX);
}
// if no permission to read, return nullptr
- if (::access(target.c_str(), R_OK) != 0)
- return nullptr;
- else
+ if (isReadable(target))
return statptr;
+ else
+ return nullptr;
}
}
void __createFile(const std::string &path)
{
- if (access(path.c_str(), R_OK | W_OK) == 0)
+ if (::access(path.c_str(), R_OK | W_OK) == 0)
return; // already exist
int fd = creat(path.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);