static AgentDiagnosticsResult AgentDiagnosticsCheckDB(ARG_UNUSED const char *workdir, dbid id) { char *dbpath = DBIdToPath(id); char *error = DBPrivDiagnose(dbpath); if (error) { free(dbpath); return AgentDiagnosticsResultNew(false, error); } else { int ret = CheckTokyoDBCoherence(dbpath); free(dbpath); if (ret) { return AgentDiagnosticsResultNew(false, xstrdup("Internal DB coherence problem")); } else { if (id == dbid_lastseen) { if (IsLastSeenCoherent() == false) { return AgentDiagnosticsResultNew(false, xstrdup("Lastseen DB data coherence problem")); } } return AgentDiagnosticsResultNew(true, xstrdup("OK")); } } }
/** * @brief removes all traces of entry 'input' from lastseen DB * * @param[in] key digest (SHA/MD5 format) or free host name string * @param[in] must_be_coherent. false : delete if lastseen is incoherent, * true : don't if lastseen is incoherent * @param[out] equivalent. If input is a host, return its corresponding * digest. If input is a digest, return its * corresponding host. CAN BE NULL! If equivalent * is null, it stays as NULL * @retval 0 if entry was deleted, <>0 otherwise */ int RemoveKeysFromLastSeen(const char *input, bool must_be_coherent, char *equivalent) { bool is_coherent = false; if (must_be_coherent == true) { is_coherent = IsLastSeenCoherent(); if (is_coherent == false) { Log(LOG_LEVEL_ERR, "Lastseen database is incoherent. Will not proceed to remove entries from it."); return 254; } } bool is_digest; is_digest = IsDigestOrHost(input); if (is_digest == true) { Log(LOG_LEVEL_VERBOSE, "Removing digest '%s' from lastseen database\n", input); if (DeleteDigestFromLastSeen(input, equivalent) == false) { Log(LOG_LEVEL_ERR, "Unable to remove digest from lastseen database."); return 252; } } else { Log(LOG_LEVEL_VERBOSE, "Removing host '%s' from lastseen database\n", input); if (DeleteIpFromLastSeen(input, equivalent) == false) { Log(LOG_LEVEL_ERR, "Unable to remove host from lastseen database."); return 253; } } Log(LOG_LEVEL_INFO, "Removed corresponding entries from lastseen database."); return 0; }