Fix freshclam and sigtool logging issues

Some log statements using the old ^, !, and * logg-prefix where they
were making use a ternary to determine the log level in the log
statement.

Also sigtool and freshclam weren't outputting error log messages using
the Rust log macros e.g. `error!("...")`.
pull/900/head
Micah Snyder 2 years ago committed by Micah Snyder
parent 908324fde4
commit 5a343f6448
  1. 6
      libfreshclam/dns.c
  2. 7
      libfreshclam/libfreshclam.c
  3. 43
      libfreshclam/libfreshclam_internal.c
  4. 6
      sigtool/sigtool.c

@ -71,12 +71,12 @@ dnsquery(const char *domain, int qtype, unsigned int *ttl)
if (qtype == T_TXT)
qtype = T_ANY;
if ((len = res_query(domain, C_IN, qtype, answer, PACKETSZ)) < 0) {
logg(LOGG_INFO, "%cCan't query %s\n",
(qtype == T_TXT || qtype == T_ANY) ? '^' : '*', domain);
logg((qtype == T_TXT || qtype == T_ANY) ? LOGG_WARNING : LOGG_DEBUG, "Can't query %s\n",
domain);
return NULL;
}
#else
logg(LOGG_INFO, "%cCan't query %s\n", (qtype == T_TXT) ? '^' : '*', domain);
logg((qtype == T_TXT) ? LOGG_WARNING : LOGG_DEBUG, "Can't query %s\n", domain);
return NULL;
#endif
}

@ -56,6 +56,7 @@
// libclamav
#include "clamav.h"
#include "clamav_rust.h"
#include "others.h"
#include "regex_list.h"
#include "str.h"
@ -132,6 +133,12 @@ fc_error_t fc_initialize(fc_config *fcConfig)
return status;
}
/* Rust logging initialization */
if (!clrs_log_init()) {
cli_dbgmsg("Unexpected problem occurred while setting up rust logging... continuing without rust logging. \
Please submit an issue to https://github.com/Cisco-Talos/clamav");
}
/* Initilize libcurl */
curl_global_init(CURL_GLOBAL_ALL);

@ -987,11 +987,11 @@ static fc_error_t remote_cvdhead(
* show the more generic information from curl_easy_strerror instead.
*/
size_t len = strlen(errbuf);
logg(LOGG_INFO, "%cremote_cvdhead: Download failed (%d) ", logerr ? '!' : '^', curl_ret);
logg(logerr ? LOGG_ERROR : LOGG_WARNING, "remote_cvdhead: Download failed (%d) ", curl_ret);
if (len)
logg(LOGG_INFO, "%c Message: %s%s", logerr ? '!' : '^', errbuf, ((errbuf[len - 1] != '\n') ? "\n" : ""));
logg(logerr ? LOGG_ERROR : LOGG_WARNING, " Message: %s%s", errbuf, ((errbuf[len - 1] != '\n') ? "\n" : ""));
else
logg(LOGG_INFO, "%c Message: %s\n", logerr ? '!' : '^', curl_easy_strerror(curl_ret));
logg(logerr ? LOGG_ERROR : LOGG_WARNING, " Message: %s\n", curl_easy_strerror(curl_ret));
status = FC_ECONNECTION;
goto done;
}
@ -1057,11 +1057,11 @@ static fc_error_t remote_cvdhead(
}
default: {
if (g_proxyServer)
logg(LOGG_INFO, "%cremote_cvdhead: Unexpected response (%li) from %s (Proxy: %s:%u)\n",
logerr ? '!' : '^', http_code, server, g_proxyServer, g_proxyPort);
logg(logerr ? LOGG_ERROR : LOGG_WARNING, "remote_cvdhead: Unexpected response (%li) from %s (Proxy: %s:%u)\n",
http_code, server, g_proxyServer, g_proxyPort);
else
logg(LOGG_INFO, "%cremote_cvdhead: Unexpected response (%li) from %s\n",
logerr ? '!' : '^', http_code, server);
logg(logerr ? LOGG_ERROR : LOGG_WARNING, "remote_cvdhead: Unexpected response (%li) from %s\n",
http_code, server);
status = FC_EFAILEDGET;
goto done;
}
@ -1071,7 +1071,7 @@ static fc_error_t remote_cvdhead(
* Identify start of CVD header in response body.
*/
if (receivedData.size < CVD_HEADER_SIZE) {
logg(LOGG_INFO, "%cremote_cvdhead: Malformed CVD header (too short)\n", logerr ? '!' : '^');
logg(logerr ? LOGG_ERROR : LOGG_WARNING, "remote_cvdhead: Malformed CVD header (too short)\n");
status = FC_EFAILEDGET;
goto done;
}
@ -1087,7 +1087,7 @@ static fc_error_t remote_cvdhead(
(receivedData.buffer && !*receivedData.buffer) ||
(receivedData.buffer && !isprint(receivedData.buffer[i]))) {
logg(LOGG_INFO, "%cremote_cvdhead: Malformed CVD header (bad chars)\n", logerr ? '!' : '^');
logg(logerr ? LOGG_ERROR : LOGG_WARNING, "remote_cvdhead: Malformed CVD header (bad chars)\n");
status = FC_EFAILEDGET;
goto done;
}
@ -1098,7 +1098,7 @@ static fc_error_t remote_cvdhead(
* Parse CVD info into CVD info struct.
*/
if (!(cvdhead = cl_cvdparse(head))) {
logg(LOGG_INFO, "%cremote_cvdhead: Malformed CVD header (can't parse)\n", logerr ? '!' : '^');
logg(logerr ? LOGG_ERROR : LOGG_WARNING, "remote_cvdhead: Malformed CVD header (can't parse)\n");
status = FC_EFAILEDGET;
goto done;
} else {
@ -1289,17 +1289,18 @@ static fc_error_t downloadFile(
* show the more generic information from curl_easy_strerror instead.
*/
size_t len = strlen(errbuf);
logg(LOGG_INFO, "%cDownload failed (%d) ", logerr ? '!' : '^', curl_ret);
logg(logerr ? LOGG_ERROR : LOGG_WARNING, "Download failed (%d) ", curl_ret);
if (len)
logg(LOGG_INFO, "%c Message: %s%s", logerr ? '!' : '^', errbuf, ((errbuf[len - 1] != '\n') ? "\n" : ""));
logg(logerr ? LOGG_ERROR : LOGG_WARNING, " Message: %s%s", errbuf, ((errbuf[len - 1] != '\n') ? "\n" : ""));
else
logg(LOGG_INFO, "%c Message: %s\n", logerr ? '!' : '^', curl_easy_strerror(curl_ret));
logg(logerr ? LOGG_ERROR : LOGG_WARNING, " Message: %s\n", curl_easy_strerror(curl_ret));
status = FC_ECONNECTION;
goto done;
}
/* Check HTTP code */
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
logg(LOGG_WARNING, " ******* RESULT %ld, SIZE: %zu ******* \n", http_code, receivedFile.size);
switch (http_code) {
case 200:
case 206: {
@ -1363,11 +1364,11 @@ static fc_error_t downloadFile(
}
default: {
if (g_proxyServer)
logg(LOGG_INFO, "%cdownloadFile: Unexpected response (%li) from %s (Proxy: %s:%u)\n",
logerr ? '!' : '^', http_code, url, g_proxyServer, g_proxyPort);
logg(logerr ? LOGG_ERROR : LOGG_WARNING, "downloadFile: Unexpected response (%li) from %s (Proxy: %s:%u)\n",
http_code, url, g_proxyServer, g_proxyPort);
else
logg(LOGG_INFO, "%cdownloadFile: Unexpected response (%li) from %s\n",
logerr ? '!' : '^', http_code, url);
logg(logerr ? LOGG_ERROR : LOGG_WARNING, "downloadFile: Unexpected response (%li) from %s\n",
http_code, url);
status = FC_EFAILEDGET;
}
}
@ -1426,7 +1427,7 @@ static fc_error_t getcvd(
status = ret;
goto done;
} else if (ret > FC_UPTODATE) {
logg(LOGG_INFO, "%cCan't download %s from %s\n", logerr ? '!' : '^', cvdfile, url);
logg(logerr ? LOGG_ERROR : LOGG_WARNING, "Can't download %s from %s\n", cvdfile, url);
status = ret;
goto done;
}
@ -1634,7 +1635,7 @@ static fc_error_t downloadPatch(
if (ret == FC_EEMPTYFILE) {
logg(LOGG_INFO, "Empty script %s, need to download entire database\n", patch);
} else {
logg(LOGG_INFO, "%cdownloadPatch: Can't download %s from %s\n", logerr ? '!' : '^', patch, url);
logg(logerr ? LOGG_ERROR : LOGG_WARNING, "downloadPatch: Can't download %s from %s\n", patch, url);
}
status = ret;
goto done;
@ -2397,7 +2398,7 @@ fc_error_t updatedb(
size_t newLocalFilenameLen = 0;
if (FC_SUCCESS != buildcld(tmpdir, database, tmpfile, g_bCompressLocalDatabase)) {
logg(LOGG_ERROR, "updatedb: Incremental update failed. Failed to build CLD.\n");
status = FC_EFAILEDUPDATE;
status = FC_EBADCVD;
goto done;
}
@ -2611,7 +2612,7 @@ fc_error_t updatecustomdb(
logg(LOGG_INFO, "%s is up-to-date (version: custom database)\n", databaseName);
goto up_to_date;
} else if (ret > FC_UPTODATE) {
logg(LOGG_INFO, "%cCan't download %s from %s\n", logerr ? '!' : '^', databaseName, url);
logg(logerr ? LOGG_ERROR : LOGG_WARNING, "Can't download %s from %s\n", databaseName, url);
status = ret;
goto done;
}

@ -3475,6 +3475,12 @@ int main(int argc, char **argv)
}
ret = 1;
/* Rust logging initialization */
if (!clrs_log_init()) {
cli_dbgmsg("Unexpected problem occurred while setting up rust logging... continuing without rust logging. \
Please submit an issue to https://github.com/Cisco-Talos/clamav");
}
opts = optparse(NULL, argc, argv, 1, OPT_SIGTOOL, 0, NULL);
if (!opts) {
mprintf(LOGG_ERROR, "Can't parse command line options\n");

Loading…
Cancel
Save