Repository navigation
clamd: Add an option to toggle SHUTDOWN, RELOAD, STATS and VERSION - #1502
Conversation
val-ms
left a comment
There was a problem hiding this comment.
Thank you for submitting a proposed fix for this. I'm good with this solution.
Can you please document the new options in this following locations?
- https://github.com/Cisco-Talos/clamav/blob/main/docs/man/clamd.conf.5.in
- https://github.com/Cisco-Talos/clamav/blob/main/etc/clamd.conf.sample
- https://github.com/Cisco-Talos/clamav/blob/main/win32/conf_examples/clamd.conf.sample
The clang-format test has an issue with formatting, here:
clamd/session.c:568:75: error: code should be clang-formatted [-Wclang-format-violations]
/* we set reload flag, and we'll reload before closing the
^
The code change makes sense to me though. I'll run this through the test pipelines to verify there aren't unexpected issues and also test it locally. Unless something comes up I don't expect any other code changes to request.
…conf manpage and the clamd.conf sample files
|
I added documentation to the manpage and the sample configs (hope it is intelligible), and also got rid of the scary formatting error :) |
val-ms
left a comment
There was a problem hiding this comment.
I discussed this with teammates who suggested two UX improvements:
-
clamdtopwill not work whenEnableStatsCommandisno. It would be great if you could add a check in clamdtop to see if this feature is disabled and log an erro rmessage explaining that it is disabled. -
the
freshclam.confoptionNotifyClamdwill not work ifEnableReloadCommandisno. It would be great if you could havefreshclamcheck if the reload command is disabled before attempting, so it can print a helpful warning to explain why clamd can't be notified. I think the change would go right here: https://github.com/Cisco-Talos/clamav/blob/main/freshclam/notify.c#L64
Should I consider the config options or the response from clamd for checking if the command is enabled? Edit: Checking the response would make it more flexible (allowing it to work with remote clamd servers), so I'll go with that for now. |
Looks like clamdtop also requires |
Oh thanks for catching that! |
|
I can't use |
Is implemented now :) |
val-ms
left a comment
There was a problem hiding this comment.
The code change looks great. Thank you very much for this work.
I did manual testing to verify the new features and am happy with the results.
For EnableReloadCommand, I first tested that a reload would still happen with NotifyClamd configured.
Then I tested with EnableReloadCommand no:
❯ ./install/bin/freshclam --update-db=test
ClamAV update process started at Mon Jun 2 09:59:26 2025
test database available for update (local version: 2, remote version: 10)
Time: 0.2s, ETA: 0.0s [========================>] 10.19KiB/10.19KiB
Testing database: '/home/micah/dev/clamav/clamav-2/build/install/share/clamav/tmp.23d6e455ae/test.cvd' ...
Database test passed.
test.cvd updated (version: 10, sigs: 18, f-level: 81, builder: micasnyd)
WARNING: Clamd was NOT notified: The RELOAD command is disabled. Consider enabling it in the clamd configuration!
I also confirmed that clamd did not reload.
For EnableVersionCommand, I tested clamdscan --version and freshclam --version before and after setting EnableVersionCommand no.
Before:
clamav-2/build on PR-1502 [$?] via C v9.4.0-gcc via △ v3.30.0
❯ ./install/bin/clamdscan --version
ClamAV 1.5.0-beta/27647/Sat May 24 04:30:52 2025
clamav-2/build on PR-1502 [$?] via C v9.4.0-gcc via △ v3.30.0
❯ ./install/bin/freshclam --version
ClamAV 1.5.0-beta/27647/Sat May 24 04:30:52 2025
With EnableVersionCommand no set:
clamav-2/build on PR-1502 [$?] via C v9.4.0-gcc via △ v3.30.0
❯ ./install/bin/clamdscan --version
COMMAND UNAVAILABLE
clamav-2/build on PR-1502 [$?] via C v9.4.0-gcc via △ v3.30.0
❯ ./install/bin/freshclam --version
ClamAV 1.5.0-beta/27647/Sat May 24 04:30:52 2025
It would be a little bit better if clamdscan were to return the local version of the clamdscan program if the VERSION command is unavailable, as it does when clamd is not running. E.g.:
❯ ./install/bin/clamdscan --version
ERROR: Could not connect to clamd on LocalSocket /tmp/clamd.sock: No such file or directory
ClamAV 1.5.0-beta
I'm thinking something like this:
diff --git a/clamdscan/client.c b/clamdscan/client.c
index 54f28c225..0caf4ddc4 100644
--- a/clamdscan/client.c
+++ b/clamdscan/client.c
@@ -357,6 +357,14 @@ int get_clamd_version(const struct optstruct *opts)
logg(LOGG_ERROR, "Error occurred while receiving version information.\n");
break;
}
+
+ // Check if the response was "COMMAND UNAVAILABLE"
+ if (len >= 19 && memcmp(buff, "COMMAND UNAVAILABLE", 19) == 0) {
+ logg(LOGG_WARNING, "VERSION command disabled in clamd.\n");
+ closesocket(sockd);
+ return 2;
+ }
+
printf("%s\n", buff);
}I also confirmed that clamdtop prints the nice error message when EnableVersionCommand no:
❯ ./install/bin/clamdtop
__ ____
_____/ /___ _____ ___ ____/ / /_____ ____
/ ___/ / __ `/ __ `__ \/ __ / __/ __ \/ __ \
/ /__/ / /_/ / / / / / / /_/ / /_/ /_/ / /_/ /
\___/_/\__,_/_/ /_/ /_/\__,_/\__/\____/ .___/
/_/
Connecting to: /tmp/clamd.sock
VERSION command unavailable, consider enabling it in the clamd configuration.
And when EnableStatsCommand no:
❯ ./install/bin/clamdtop
__ ____
_____/ /___ _____ ___ ____/ / /_____ ____
/ ___/ / __ `/ __ `__ \/ __ / __/ __ \/ __ \
/ /__/ / /_/ / / / / / / /_/ / /_/ /_/ / /_/ /
\___/_/\__,_/_/ /_/ /_/\__,_/\__/\____/ .___/
/_/
Connecting to: /tmp/clamd.sock
STATS command unavailable, consider enabling it in the clamd configuration.
|
Fixed the formatting issues, ran the check locally & it succeeded |
…ION command disabled
-> thanks for the suggested code, I only changed the warning and comment a little :D |
val-ms
left a comment
There was a problem hiding this comment.
I love it! Thanks so much for your thoughtful effort on this work.
Sysadmins may need to prevent users from doing stuff like shutting down clamd, constantly reloading, or gathering information about the daemon, so I added some config options to control that.
Here are the config options with their defaults:
If the client calls a deactived command, the server replies with
UNKNOWN COMMANDCOMMAND UNAVAILABLEsee #347, #922 and #1169