CREATE TABLE IF NOT EXISTS SCAN_REQUEST (
dir TEXT NOT NULL,
last_scan INTEGER NOT NULL,
- data_version TEXT NOT NULL,
PRIMARY KEY(dir)
);
filepath_idx INTEGER PRIMARY KEY AUTOINCREMENT,
file_path TEXT NOT NULL,
idx INTEGER NOT NULL,
- data_version TEXT NOT NULL,
malware_name TEXT NOT NULL,
detailed_url TEXT NOT NULL,
severity INTEGER NOT NULL,
CREATE TABLE IF NOT EXISTS DETECTED_MALWARE_CLOUD (
idx INTEGER NOT NULL,
pkg_id TEXT NOT NULL,
- data_version TEXT NOT NULL,
malware_name TEXT NOT NULL,
detailed_url TEXT NOT NULL,
severity INTEGER NOT NULL,
);
CREATE VIEW IF NOT EXISTS [join_detecteds_cloud_by_name] AS
- SELECT N.name, D.data_version, D.malware_name, D.detailed_url, D.severity,
+ SELECT N.name, D.malware_name, D.detailed_url, D.severity,
D.detected_time, D.pkg_id, N.is_ignored
FROM NAMES AS N INNER JOIN DETECTED_MALWARE_CLOUD AS D ON N.idx = D.idx;
CREATE VIEW IF NOT EXISTS [join_p_d] AS
- SELECT N.idx, N.name, D.file_path, D.data_version, D.malware_name, D.detailed_url,
+ SELECT N.idx, N.name, D.file_path, D.malware_name, D.detailed_url,
D.severity, D.detected_time, P.pkg_id
FROM (PACKAGE_INFO AS P INNER JOIN DETECTED_MALWARE AS D ON P.worst_filepath_idx = D.filepath_idx)
AS J INNER JOIN NAMES AS N ON J.idx = N.idx;
CREATE VIEW IF NOT EXISTS [join_detecteds_by_name] AS
- SELECT N.name, J.file_path, J.data_version, J.malware_name, J.detailed_url,
+ SELECT N.name, J.file_path, J.malware_name, J.detailed_url,
J.severity, J.detected_time, J.pkg_id, N.is_ignored
FROM (
- SELECT D.idx, D.file_path, D.data_version, D.malware_name, D.detailed_url,
+ SELECT D.idx, D.file_path, D.malware_name, D.detailed_url,
D.severity, D.detected_time, P.pkg_id
FROM DETECTED_MALWARE AS D LEFT JOIN PACKAGE_INFO AS P ON D.idx = P.idx
WHERE NOT EXISTS (SELECT * FROM join_p_d WHERE idx = D.idx)
UNION
- SELECT idx, file_path, data_version, malware_name, detailed_url,
+ SELECT idx, file_path, malware_name, detailed_url,
severity, detected_time, pkg_id
FROM join_p_d)
AS J INNER JOIN NAMES AS N ON J.idx = N.idx;
CREATE VIEW IF NOT EXISTS [join_detecteds_by_file_path] AS
- SELECT N.name, D.file_path, D.data_version, D.malware_name, D.detailed_url,
+ SELECT N.name, D.file_path, D.malware_name, D.detailed_url,
D.severity, D.detected_time, P.pkg_id, N.is_ignored
FROM (DETECTED_MALWARE AS D LEFT JOIN PACKAGE_INFO AS P ON D.idx = P.idx)
AS J INNER JOIN NAMES AS N ON J.idx = N.idx;
row->targetName = stmt.getText(); // name.
row->fileInAppPath = stmt.getText(); // file_path
- row->dataVersion = stmt.getText(); // data_version
row->malwareName = stmt.getText(); // malware_name
row->detailedUrl = stmt.getText(); // detailed_url
row->severity = static_cast<csr_cs_severity_level_e>(stmt.getInt()); // severity
row->targetName = stmt.getText(); // name.
row->fileInAppPath.clear();
- row->dataVersion = stmt.getText(); // data_version
row->malwareName = stmt.getText(); // malware_name
row->detailedUrl = stmt.getText(); // detailed_url
row->severity = static_cast<csr_cs_severity_level_e>(stmt.getInt()); // severity
// SCAN_REQUEST table
//===========================================================================
-time_t Manager::getLastScanTime(const std::string &dir,
- const std::string &dataVersion)
+time_t Manager::getLastScanTime(const std::string &dir, time_t since)
{
std::lock_guard<std::mutex> l(this->m_mutex);
while (true) {
stmt.bind(current);
- stmt.bind(dataVersion);
if (stmt.step()) {
auto candidate = static_cast<time_t>(stmt.getInt64());
- if (latest < candidate)
+ if ((since < 0 || since < candidate) && latest < candidate)
latest = candidate;
}
return latest;
}
-void Manager::insertLastScanTime(const std::string &dir, time_t scanTime,
- const std::string &dataVersion)
+void Manager::insertLastScanTime(const std::string &dir, time_t scanTime)
{
std::lock_guard<std::mutex> l(this->m_mutex);
stmt.bind(dir);
stmt.bind(static_cast<sqlite3_int64>(scanTime));
- stmt.bind(dataVersion);
stmt.exec();
}
row->targetName = stmt.getText(); // name
row->fileInAppPath = stmt.getText(); // file_path
- row->dataVersion = stmt.getText(); // data_version
row->malwareName = stmt.getText(); // malware_name
row->detailedUrl = stmt.getText(); // detailed_url
row->severity = static_cast<csr_cs_severity_level_e>(stmt.getInt()); // severity
return row;
}
-void Manager::insertDetectedFile(const std::string &filepath, const CsDetected &d,
- const std::string &dataVersion)
+void Manager::insertDetectedFile(const std::string &filepath, const CsDetected &d)
{
std::lock_guard<std::mutex> l(this->m_mutex);
this->insertName(filepath);
- this->insertDetected(d, filepath, dataVersion);
+ this->insertDetected(d, filepath);
}
void Manager::insertDetectedFileInApp(const std::string &pkgpath, const std::string &filepath,
- const CsDetected &d, const std::string &dataVersion)
+ const CsDetected &d)
{
std::lock_guard<std::mutex> l(this->m_mutex);
this->insertName(pkgpath);
- this->insertDetected(d, filepath, dataVersion);
+ this->insertDetected(d, filepath);
}
void Manager::insertDetectedAppByCloud(const std::string &name, const std::string &pkgId,
- const CsDetected &d, const std::string &dataVersion)
+ const CsDetected &d)
{
std::lock_guard<std::mutex> l(this->m_mutex);
this->insertName(name);
- this->insertDetectedCloud(d, pkgId, name, dataVersion);
+ this->insertDetectedCloud(d, pkgId, name);
}
void Manager::insertName(const std::string &name)
stmt.exec();
}
-void Manager::insertDetected(const CsDetected &d, const std::string &filepath,
- const std::string &dataVersion)
+void Manager::insertDetected(const CsDetected &d, const std::string &filepath)
{
Statement stmt(this->m_conn, Query::INS_DETECTED);
stmt.bind(filepath);
stmt.bind(d.targetName);
- stmt.bind(dataVersion);
stmt.bind(d.malwareName);
stmt.bind(d.detailedUrl);
stmt.bind(static_cast<int>(d.severity));
}
void Manager::insertDetectedCloud(const CsDetected &d, const std::string &pkgId,
- const std::string &name, const std::string &dataVersion)
+ const std::string &name)
{
Statement stmt(this->m_conn, Query::INS_DETECTED_CLOUD);
stmt.bind(name);
stmt.bind(pkgId);
- stmt.bind(dataVersion);
stmt.bind(d.malwareName);
stmt.bind(d.detailedUrl);
stmt.bind(static_cast<int>(d.severity));
stmt.exec();
}
-void Manager::deleteDetectedDeprecatedOnDir(const std::string &dir,
- const std::string &dataVersion)
+void Manager::deleteDetectedDeprecated(time_t t)
{
std::lock_guard<std::mutex> l(this->m_mutex);
- Statement stmt(this->m_conn, Query::DEL_DETECTED_DEPRECATED_ON_DIR);
+ Statement stmt(this->m_conn, Query::DEL_DETECTED_DEPRECATED);
- stmt.bind(dir);
- stmt.bind(dataVersion);
+ stmt.bind(static_cast<sqlite3_int64>(t));
stmt.exec();
+
+ Statement stmt2(this->m_conn, Query::DEL_DETECTED_DEPRECATED_CLOUD);
+
+ stmt2.bind(static_cast<sqlite3_int64>(t));
+ stmt2.exec();
}
} // namespace Db
#include <memory>
#include <map>
#include <mutex>
+#include <ctime>
#include "db/connection.h"
#include "db/row.h"
void setEngineState(csr_engine_id_e, csr_state_e);
// SCAN_REQUEST
- time_t getLastScanTime(const std::string &dir, const std::string &dataVersion);
- void insertLastScanTime(const std::string &dir, time_t scanTime,
- const std::string &dataVersion);
+ time_t getLastScanTime(const std::string &dir, time_t since);
+ void insertLastScanTime(const std::string &dir, time_t scanTime);
void deleteLastScanTime(const std::string &dir);
void cleanLastScanTime();
RowShPtrs getDetectedByFilepathOnDir(const std::string &dir);
RowShPtr getWorstByPkgPath(const std::string &pkgPath);
- void insertDetectedFile(const std::string &filepath, const CsDetected &d,
- const std::string &dataVersion);
+ void insertDetectedFile(const std::string &filepath, const CsDetected &d);
void insertDetectedFileInApp(const std::string &pkgpath, const std::string &filepath,
- const CsDetected &d, const std::string &dataVersion);
+ const CsDetected &d);
void insertDetectedAppByCloud(const std::string &name, const std::string &pkgId,
- const CsDetected &d, const std::string &dataVersion);
+ const CsDetected &d);
void insertWorst(const std::string &pkgId, const std::string &name,
const std::string &filepath);
void updateIgnoreFlag(const std::string &name, bool flag);
void deleteDetectedByNameOnPath(const std::string &path);
void deleteDetectedByFilepathOnPath(const std::string &path);
- void deleteDetectedDeprecatedOnDir(const std::string &dir,
- const std::string &dataVersion);
+ void deleteDetectedDeprecated(time_t t);
private:
RowShPtrs getDetectedByNameOnDir(const std::string &dir);
RowShPtrs getDetectedCloudByNameOnDir(const std::string &dir);
void insertName(const std::string &name);
- void insertDetected(const CsDetected &d, const std::string &filename,
- const std::string &dataVersion);
+ void insertDetected(const CsDetected &d, const std::string &filename);
void insertDetectedCloud(const CsDetected &d, const std::string &pkgId,
- const std::string &name, const std::string &dataVersion);
+ const std::string &name);
void resetDatabase();
bool isTableExist(const std::string &name);
"select id, state from ENGINE_STATE";
const std::string SEL_SCAN_REQUEST =
- "select last_scan from SCAN_REQUEST where dir = ? and data_version = ?";
+ "select last_scan from SCAN_REQUEST where dir = ?";
const std::string INS_SCAN_REQUEST =
- "insert or replace into SCAN_REQUEST (dir, last_scan, data_version)"
- " values (?, ?, ?)";
+ "insert or replace into SCAN_REQUEST (dir, last_scan)"
+ " values (?, ?)";
const std::string DEL_SCAN_REQUEST_BY_DIR =
"delete from SCAN_REQUEST where dir = ?";
"delete from SCAN_REQUEST";
const std::string SEL_DETECTED_CLOUD_BY_NAME_ON_PATH =
- "select name, data_version, malware_name, detailed_url, severity, detected_time,"
+ "select name, malware_name, detailed_url, severity, detected_time,"
" pkg_id, is_ignored"
" from join_detecteds_cloud_by_name"
" where name = ?";
const std::string SEL_DETECTED_BY_NAME_ON_PATH =
- "select name, file_path, data_version, malware_name, detailed_url, severity,"
+ "select name, file_path, malware_name, detailed_url, severity,"
" detected_time, pkg_id, is_ignored"
" from join_detecteds_by_name"
" where name = ?";
const std::string SEL_DETECTED_CLOUD_BY_NAME_ON_DIR =
- "select name, data_version, malware_name, detailed_url, severity, detected_time,"
+ "select name, malware_name, detailed_url, severity, detected_time,"
" pkg_id, is_ignored"
" from join_detecteds_cloud_by_name"
" where name like ? || '%'";
const std::string SEL_DETECTED_BY_NAME_ON_DIR =
- "select name, file_path, data_version, malware_name, detailed_url, severity,"
+ "select name, file_path, malware_name, detailed_url, severity,"
" detected_time, pkg_id, is_ignored"
" from join_detecteds_by_name"
" where name like ? || '%'";
const std::string SEL_DETECTED_BY_FILEPATH_ON_DIR =
- "select name, file_path, data_version, malware_name, detailed_url, severity,"
+ "select name, file_path, malware_name, detailed_url, severity,"
" detected_time, pkg_id, is_ignored"
" from join_detecteds_by_file_path"
" where file_path like ? || '%'";
const std::string SEL_WORST_BY_PKGPATH =
- "select name, file_path, data_version, malware_name, detailed_url, severity,"
+ "select name, file_path, malware_name, detailed_url, severity,"
" detected_time, pkg_id"
" from join_p_d"
" where name = ?";
"insert or replace into NAMES(name) values(?)";
const std::string INS_DETECTED_CLOUD =
- "insert or replace into DETECTED_MALWARE_CLOUD(idx, pkg_id, data_version,"
+ "insert or replace into DETECTED_MALWARE_CLOUD(idx, pkg_id,"
" malware_name, detailed_url, severity,"
" detected_time)"
- " values((select idx from NAMES where name = ?), ?, ?, ?, ?, ?, ?)";
+ " values((select idx from NAMES where name = ?), ?, ?, ?, ?, ?)";
const std::string INS_DETECTED =
- "insert or replace into DETECTED_MALWARE(file_path, idx, data_version, malware_name,"
+ "insert or replace into DETECTED_MALWARE(file_path, idx, malware_name,"
" detailed_url, severity, detected_time)"
- " values(?, (select idx from NAMES where name = ?), ?, ?, ?, ?, ?)";
+ " values(?, (select idx from NAMES where name = ?), ?, ?, ?, ?)";
const std::string INS_WORST =
"insert or replace into PACKAGE_INFO(pkg_id, idx, worst_filepath_idx)"
const std::string DEL_DETECTED_BY_FILEPATH_ON_PATH =
"delete from DETECTED_MALWARE where file_path = ?";
-const std::string DEL_DETECTED_DEPRECATED_ON_DIR =
- "delete from DETECTED_MALWARE where file_path like ? || '%' "
- " and data_version != ?";
+const std::string DEL_DETECTED_DEPRECATED =
+ "delete from DETECTED_MALWARE where detected_time < ?";
+
+const std::string DEL_DETECTED_DEPRECATED_CLOUD =
+ "delete from DETECTED_MALWARE_CLOUD where detected_time < ?";
} // namespace Query
} // namespace Db
struct Row : public Csr::CsDetected {
std::string fileInAppPath; // for case of file in app
- std::string dataVersion; // engine's data version
bool isIgnored;
Row() : isIgnored(false) {}
}));
}
-void CsLoader::getEngineLatestUpdateTime(csre_cs_context_h c, time_t *ptime)
+time_t CsLoader::getEngineLatestUpdateTime(csre_cs_context_h c)
{
- if (c == nullptr || ptime == nullptr)
+ if (c == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "cs loader get latest update time");
- this->toException(this->m_pc.fpGetEngineLatestUpdateTime(c, ptime));
+ time_t t;
+
+ this->toException(this->m_pc.fpGetEngineLatestUpdateTime(c, &t));
+
+ return t;
}
void CsLoader::getEngineActivated(csre_cs_context_h c, csre_cs_activated_e *pactivated)
void getEngineName(csre_cs_context_h, std::string &);
void getEngineVersion(csre_cs_context_h, std::string &);
void getEngineDataVersion(csre_cs_context_h, std::string &);
- void getEngineLatestUpdateTime(csre_cs_context_h, time_t *);
+ time_t getEngineLatestUpdateTime(csre_cs_context_h);
void getEngineActivated(csre_cs_context_h, csre_cs_activated_e *);
void getEngineVendorLogo(csre_cs_context_h, std::vector<unsigned char> &);
if (this->m_loader) {
CsEngineContext csEngineContext(this->m_loader);
this->m_loader->getEngineDataVersion(csEngineContext.get(), this->m_dataVersion);
+ this->m_db->deleteDetectedDeprecated(
+ this->m_loader->getEngineLatestUpdateTime(csEngineContext.get()));
}
}
detected.isApp = true;
detected.pkgId = pkgId;
- this->m_db->insertDetectedAppByCloud(pkgPath, pkgId, detected, this->m_dataVersion);
+ this->m_db->insertDetectedAppByCloud(pkgPath, pkgId, detected);
return this->handleAskUser(context, detected);
}
CsEngineContext engineContext(this->m_loader);
auto &c = engineContext.get();
- auto lastScanTime = this->m_db->getLastScanTime(pkgPath, this->m_dataVersion);
+ auto t = this->m_loader->getEngineLatestUpdateTime(c);
+ auto lastScanTime = this->m_db->getLastScanTime(pkgPath, t);
// traverse files in app and take which is more danger than riskiest
auto visitor = FsVisitor::create(pkgPath, lastScanTime);
candidate.isApp = true;
candidate.pkgId = pkgId;
- this->m_db->insertDetectedFileInApp(pkgPath, file->getPath(), candidate,
- this->m_dataVersion);
+ this->m_db->insertDetectedFileInApp(pkgPath, file->getPath(), candidate);
if (!riskiest) {
riskiest.reset(new CsDetected(std::move(candidate)));
}
}
- this->m_db->insertLastScanTime(pkgPath, starttime, this->m_dataVersion);
+ this->m_db->insertLastScanTime(pkgPath, starttime);
return riskiest;
}
auto d = this->convert(result, filepath, timestamp);
- this->m_db->insertDetectedFile(d.targetName, d, this->m_dataVersion);
+ this->m_db->insertDetectedFile(d.targetName, d);
return this->handleAskUser(context, d, std::forward<FilePtr>(fileptr));
}
// if history exist, fileptr can be null because of modified since value
// from history.
- if (history)
- fileptr = File::createIfModified(target, static_cast<time_t>(history->ts));
- else
+ if (history) {
+ CsEngineContext engineContext(this->m_loader);
+ auto t = this->m_loader->getEngineLatestUpdateTime(engineContext.get());
+ if (t < history->ts)
+ fileptr = File::createIfModified(target, history->ts);
+ else
+ fileptr = File::create(target);
+ } else {
fileptr = File::create(target);
+ }
// non-null fileptr means the file is modified since the last history
// OR there's no history at all.
if (this->m_db->getEngineState(CSR_ENGINE_CS) != CSR_STATE_ENABLE)
ThrowExc(CSR_ERROR_ENGINE_DISABLED, "engine is disabled");
- auto lastScanTime = this->m_db->getLastScanTime(dir, this->m_dataVersion);
+ CsEngineContext engineContext(this->m_loader);
+
+ auto t = this->m_loader->getEngineLatestUpdateTime(engineContext.get());
+ auto lastScanTime = this->m_db->getLastScanTime(dir, t);
auto visitor = FsVisitor::create(dir, lastScanTime);
RawBuffer CsLogic::setDirTimestamp(const std::string &dir, time_t ts)
{
- this->m_db->insertLastScanTime(dir, ts, this->m_dataVersion);
+ this->m_db->insertLastScanTime(dir, ts);
return BinaryQueue::Serialize(CSR_ERROR_NONE).pop();
}
CsEngineContext engineContext(this->m_cs);
auto &c = engineContext.get();
- time_t value;
- this->m_cs->getEngineLatestUpdateTime(c, &value);
-
- int64_t ts64 = static_cast<int64_t>(value);
+ auto ts64 = static_cast<int64_t>(this->m_cs->getEngineLatestUpdateTime(c));
return BinaryQueue::Serialize(CSR_ERROR_NONE, ts64).pop();
} else {
WpEngineContext engineContext(this->m_wp);
auto &c = engineContext.get();
- time_t value;
- this->m_wp->getEngineLatestUpdateTime(c, &value);
-
- int64_t ts64 = static_cast<int64_t>(value);
+ auto ts64 = static_cast<int64_t>(this->m_wp->getEngineLatestUpdateTime(c));
return BinaryQueue::Serialize(CSR_ERROR_NONE, ts64).pop();
}
}));
}
-void WpLoader::getEngineLatestUpdateTime(csre_wp_context_h c, time_t *ptime)
+time_t WpLoader::getEngineLatestUpdateTime(csre_wp_context_h c)
{
- if (c == nullptr || ptime == nullptr)
+ if (c == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "wp loader get latest update time");
- this->toException(this->m_pc.fpGetEngineLatestUpdateTime(c, ptime));
+ time_t t;
+
+ this->toException(this->m_pc.fpGetEngineLatestUpdateTime(c, &t));
+
+ return t;
}
void WpLoader::getEngineActivated(csre_wp_context_h c, csre_wp_activated_e *pactivated)
void getEngineName(csre_wp_context_h, std::string &);
void getEngineVersion(csre_wp_context_h, std::string &);
void getEngineDataVersion(csre_wp_context_h, std::string &);
- void getEngineLatestUpdateTime(csre_wp_context_h, time_t *);
+ time_t getEngineLatestUpdateTime(csre_wp_context_h);
void getEngineActivated(csre_wp_context_h, csre_wp_activated_e *);
void getEngineVendorLogo(csre_wp_context_h, std::vector<unsigned char> &);
#include <fstream>
#include <iostream>
#include <climits>
+#include <ctime>
+#include <cstring>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
//==============================================================================
// static variables
//==============================================================================
-static std::string g_resdir;
-static std::string g_workingdir;
+static std::string g_private_db_path;
+static std::string g_private_logo_path;
static std::list<csret_cs_malware_s> g_virus_sig;
//==============================================================================
// threat_type=RISKY
// detailed_url=http://medium.malware.com
// signature=RISKY_MALWARE
- std::ifstream f(path.c_str());
+ std::ifstream f(path.c_str(), std::ifstream::in);
if (!f.is_open())
return CSRET_CS_ERROR_NO_SIGNATURE_FILE;
ptr->engineVersion = ENGINE_VERSION;
ptr->dataVersion = ENGINE_VERSION;
- int ret = csret_cs_read_binary(g_resdir + "/" PRIVATE_LOGO_FILE, ptr->logoImage);
+ int ret = csret_cs_read_binary(g_private_logo_path, ptr->logoImage);
if (ret != CSRE_ERROR_NONE) {
delete ptr;
}
struct stat attrib;
-
- stat(PRIVATE_DB_NAME, &attrib);
+ ::memset(&attrib, 0x00, sizeof(attrib));
+ ret = ::stat(g_private_db_path.c_str(), &attrib);
+ if (ret != 0) {
+ delete ptr;
+ return CSRET_CS_ERROR_NO_SIGNATURE_FILE;
+ }
ptr->latestUpdate = attrib.st_mtime;
if (ro_res_dir == nullptr || rw_working_dir == nullptr)
return CSRE_ERROR_INVALID_PARAMETER;
- g_resdir = ro_res_dir;
- g_workingdir = rw_working_dir;
+ g_private_db_path = std::string(rw_working_dir) + "/" PRIVATE_DB_NAME;
+ g_private_logo_path = std::string(ro_res_dir) + "/" PRIVATE_LOGO_FILE;
g_virus_sig.clear();
- return csret_cs_read_virus_signatures(g_workingdir + "/" PRIVATE_DB_NAME);
+ return csret_cs_read_virus_signatures(g_private_db_path);
}
API
Handle h;
- time_t time = 0;
- h.loader.getEngineLatestUpdateTime(h.context, &time);
+ auto time = h.loader.getEngineLatestUpdateTime(h.context);
+ BOOST_MESSAGE("engine latest update time: " << time);
EXCEPTION_GUARD_END
}
std::string dataVersion = "1.0.0";
db.cleanLastScanTime();
- ASSERT_IF(db.getLastScanTime(dir, dataVersion), -1);
- db.insertLastScanTime(dir, scantime, dataVersion);
+ ASSERT_IF(db.getLastScanTime(dir, -1), -1);
+ db.insertLastScanTime(dir, scantime);
- db.insertLastScanTime("/opt/data", scantime + 100, dataVersion);
- db.insertLastScanTime("/opt/data/etc", scantime + 200, dataVersion);
+ db.insertLastScanTime("/opt/data", scantime + 100);
+ db.insertLastScanTime("/opt/data/etc", scantime + 200);
- ASSERT_IF(db.getLastScanTime(dir, dataVersion), scantime);
+ ASSERT_IF(db.getLastScanTime(dir, -1), scantime);
db.cleanLastScanTime();
EXCEPTION_GUARD_END
std::string initDataVersion = "1.0.0";
std::string changedDataVersion = "2.0.0";
+ auto starttime = ::time(nullptr);
+
// insert
CsDetected malware1;
malware1.targetName = "/opt/testmalware1";
malware1.severity = CSR_CS_SEVERITY_MEDIUM;
malware1.malwareName = "testmalware1";
malware1.detailedUrl = "http://detailed.malware.com";
- malware1.ts = 100;
+ malware1.ts = 1;
CsDetected malware2;
malware2.targetName = "/opt/testmalware2";
malware2.severity = CSR_CS_SEVERITY_HIGH;
malware2.malwareName = "testmalware2";
malware2.detailedUrl = "http://detailed2.malware.com";
- malware2.ts = 210;
+ malware2.ts = 2;
CsDetected malware3;
malware3.targetName = "/opt/testmalware3";
malware3.severity = CSR_CS_SEVERITY_LOW;
malware3.malwareName = "testmalware3";
malware3.detailedUrl = "http://detailed3.malware.com";
- malware3.ts = 310;
+ malware3.ts = starttime;
// select test with vacant data
auto detected = db.getDetectedByNameOnPath(malware1.targetName);
auto detectedList = db.getDetectedAllByNameOnDir("/opt");
ASSERT_IF(detectedList.empty(), true);
- db.insertDetectedFile(malware1.targetName, malware1, initDataVersion);
+ db.insertDetectedFile(malware1.targetName, malware1);
detected = db.getDetectedByNameOnPath(malware1.targetName);
checkSameMalware(malware1, *detected);
- ASSERT_IF(detected->dataVersion, initDataVersion);
ASSERT_IF(detected->isIgnored, false);
- db.insertDetectedFile(malware2.targetName, malware2, initDataVersion);
+ db.insertDetectedFile(malware2.targetName, malware2);
db.updateIgnoreFlag(malware2.targetName, true);
detected = db.getDetectedByNameOnPath(malware2.targetName);
checkSameMalware(malware2, *detected);
- ASSERT_IF(detected->dataVersion, initDataVersion);
ASSERT_IF(detected->isIgnored, true);
// getDetectedMalwares test
ASSERT_IF(detected->isIgnored, true);
// deleteDeprecatedDetectedMalwares test
- db.insertDetectedFile(malware3.targetName, malware3, changedDataVersion);
- db.deleteDetectedDeprecatedOnDir("/opt", changedDataVersion);
+ db.insertDetectedFile(malware3.targetName, malware3);
+ db.deleteDetectedDeprecated(3);
detected = db.getDetectedByNameOnPath(malware3.targetName);
checkSameMalware(malware3, *detected);
- ASSERT_IF(detected->dataVersion, changedDataVersion);
ASSERT_IF(detected->isIgnored, false);
CHECK_IS_NULL(db.getDetectedByNameOnPath(malware1.targetName));
Handle h;
- time_t time = 0;
- h.loader.getEngineLatestUpdateTime(h.context, &time);
+ auto time = h.loader.getEngineLatestUpdateTime(h.context);
+ BOOST_MESSAGE("engine latest update time: " << time);
EXCEPTION_GUARD_END
}