CLAMD(8)

๐Ÿ’– CLAMD(8) โ€” Clam Daemon, the anti-virus daemon ๐Ÿ’–

okay so bestie, welcome to the Clam AntiVirus corner of the man pages ๐ŸŒธ this one is Clam Daemon (that's <clamd> to its friends), and it's genuinely iconic. grab a snack, we're going in ๐Ÿซถ


โœจ NAME โœจ

clamd โ€” an anti-virus daemon ๐Ÿ’…


โœจ SYNOPSIS โœจ

clamd [options]

โœจ DESCRIPTION โœจ

so the daemon listens for incoming connections on a Unix socket and/or a TCP socket and scans files or directories on demand. it's giving very attentive, very on-call โœจ

and where does it get its whole personality? it reads the config from /etc/clamav/clamd.conf. that's the vibe source, periodt.


โœจ COMMANDS โœจ

๐Ÿ’ก the glow-up tip: it's recommended to prefix clamd commands with the letter z (eg. zSCAN). why? because that tells clamd the command will be delimited by a NULL character, and that clamd should keep reading command data until a NULL character shows up. the null delimiter is what assures you that the complete command and its entire argument get processed as a single command. no half-sent chaos, we love to see it ๐ŸŽ€

alternatively, commands may be prefixed with the letter n (e.g. nSCAN) to use a newline character as the delimiter. and clamd's replies will honour the terminator you asked for, in turn. reciprocal queen ๐Ÿ‘‘

if clamd doesn't recognize the command, or the command doesn't follow the requirements below, it will reply with an error message, and close the connection. brutal but fair ๐Ÿ’€

clamd recognizes the following commands:

PING

check the server's state. it should reply with "PONG". tiny, perfect, no notes ๐Ÿ“

VERSION

print program and database versions. this command may be disabled with EnableVersionCommand in clamd.conf. if it's disabled, clamd replies with COMMAND UNAVAILABLE.

RELOAD

reload the virus databases. this command may be disabled with EnableReloadCommand in clamd.conf. if it's disabled, clamd replies with COMMAND UNAVAILABLE.

SHUTDOWN

perform a clean exit. this command may be disabled with EnableShutdownCommand in clamd.conf. if it's disabled, clamd replies with COMMAND UNAVAILABLE.

SCAN file/directory

scan a file or a directory (recursively) with archive support enabled (unless that's disabled in clamd.conf). a full path is required โ€” no shortcuts bestie, give it the whole thing.

CONTSCAN file/directory

scan file or directory (recursively) with archive support enabled, and don't stop the scanning when a virus is found. it keeps going, resilient icon ๐Ÿฆ‹

MULTISCAN file/directory

scan a directory recursively using multiple threads (to make the scanning faster on SMP machines). if the target is not a directory, clamd falls back to non-multiscan scanning behavior.

ALLMATCHSCAN file/directory

โš ๏ธ it is mandatory to prefix this command with n or z.

ALLMATCHSCAN works just like SCAN except that it sets a mode where scanning continues after finding a match within a file. this command may be disabled with AllowAllMatchScan in clamd.conf. if it's disabled, clamd replies with an ALLMATCHSCAN error.

INSTREAM

โš ๏ธ it is mandatory to prefix this command with n or z.

scan a stream of data. the stream is sent to clamd in chunks, after INSTREAM, on the same socket on which the command was sent. this avoids the overhead of establishing new TCP connections and problems with NAT, which is lowkey genius โœจ

the format of the chunk is: '<length><data>' where <length> is the size of the following data in bytes, expressed as a 4 byte unsigned integer in network byte order, and <data> is the actual chunk. streaming is terminated by sending a zero-length chunk.

๐Ÿ’€ note: do not exceed StreamMaxLength as defined in clamd.conf, otherwise clamd will reply with INSTREAM size limit exceeded and close the connection. respect the limit, babe.

FILDES

โš ๏ธ it is mandatory to newline terminate this command, or prefix with n or z.

this command only works on UNIX domain sockets. scan a file descriptor. after issuing a FILDES command, a subsequent rfc2292/bsd4.4 style packet (with at least one dummy character) is sent to clamd carrying the file descriptor to be scanned inside the ancillary data. alternatively the file descriptor may be sent in the same packet, including the extra character.

STATS

โš ๏ธ it is mandatory to newline terminate this command, or prefix with n or z, and it is recommended to only use the z prefix.

replies with statistics about the scan queue, contents of scan queue, and memory usage. the exact reply format is subject to change in future releases. this command may be disabled with EnableStatsCommand in clamd.conf. if it's disabled, clamd replies with COMMAND UNAVAILABLE.

IDSESSION, END

โš ๏ธ it is mandatory to prefix this command with n or z, and all commands inside IDSESSION must be prefixed.

start/end a clamd session. within a session, multiple SCAN, INSTREAM, FILDES, VERSION, VERSIONCOMMANDS, PING, and STATS commands can be sent on the same socket without opening new connections. but CONTSCAN, MULTISCAN, ALLMATCHSCAN, RELOAD, and SHUTDOWN are not accepted inside an IDSESSION. house rules ๐Ÿšซ

replies from clamd will be in the form '<id>: <response>' where <id> is the request number (in ascii, starting from 1) and <response> is the usual clamd reply. the reply lines have the same delimiter as the corresponding command had. clamd will process the commands asynchronously, and reply as soon as it has finished processing.

clamd requires clients to read all the replies it sent, before sending more commands, to prevent send() deadlocks. the recommended way to implement a client that uses IDSESSION is with non-blocking sockets, and a select()/poll() loop: whenever send would block, sleep in select/poll until either you can write more data, or read more replies. note that using non-blocking sockets without the select/poll loop and alternating recv()/send() doesn't comply with clamd's requirements. do it properly, i'm begging ๐Ÿ™ˆ

if clamd detects that a client has deadlocked, it will close the connection. note that clamd may close an IDSESSION connection too if you don't follow the protocol's requirements. the client can use the PING command to keep the connection alive. friendship maintenance, basically ๐Ÿ’–

VERSIONCOMMANDS

โš ๏ธ it is mandatory to prefix this command with either n or z. it is recommended to use nVERSIONCOMMANDS.

print program and database versions, followed by "| COMMANDS:" and a space-delimited list of supported commands. Clamd <0.95 will recognize this as the VERSION command, and reply only with their version, without the commands list.

this command can be used as an easy way to check for IDSESSION support, for example. handy bestie behaviour ๐Ÿ”ฅ


๐Ÿ—‘๏ธ REMOVED COMMANDS ๐Ÿ—‘

STREAM

the legacy STREAM command is no longer supported. use INSTREAM instead. she's retired, let her rest ๐Ÿ’…


๐Ÿšซ NOT SUPPORTED COMMANDS ๐Ÿšซ

SESSION, END

start/end a clamd session which will allow you to run multiple commands per TCP session. (use IDSESSION instead) it's giving old news, sorry babe ๐Ÿ˜ญ


โœจ OPTIONS โœจ

  • -h, --help โ€” output help information and exit.
  • -V, --version โ€” print the version number and exit.
  • -F, --foreground โ€” run in foreground; do not daemonize.
  • --debug โ€” enable debug mode.
  • -c FILE, --config-file=FILE โ€” read configuration from FILE.
  • --fail-if-cvd-older-than=days โ€” return with a nonzero error code if the virus database is older than the specified number of days.
  • --datadir=DIRECTORY โ€” load signatures from DIRECTORY.
  • -p FILE, --pid=FILE โ€” write the daemon's pid to FILE.
  • --cvdcertsdir=DIR โ€” specify a directory containing the root CA cert needed to verify detached CVD digital signatures. if not provided, then clamd will look in the default directory.

โœจ ENVIRONMENT VARIABLES โœจ

clamd uses the following environment variables:

  • LD_LIBRARY_PATH โ€” may be used on startup to find the libclamunrar_iface shared library module to enable RAR archive support. ๐Ÿฆ‹
  • CVD_CERTS_DIR โ€” specify a directory containing the root CA cert needed to verify detached CVD digital signatures. if not provided, then clamd will look in the default directory.

โœจ SIGNALS โœจ

clamd recognizes the following signals:

  • SIGHUP โ€” reopen the logfile.
  • SIGUSR2 โ€” reload the signature databases.
  • SIGTERM โ€” perform a clean exit.

โœจ FILES โœจ

  • /etc/clamav/clamd.conf

โœจ CREDITS โœจ

please check the full documentation for credits. (they really said "the credits are in the full docs", and honestly? valid ๐Ÿ‘‘)


โœจ AUTHOR โœจ

Tomasz Kojm <tkojm@clamav.net> ๐Ÿ’œ


โœจ SEE ALSO โœจ

clamd.conf(5), clamdscan(1), freshclam(1), freshclam.conf(5), clamav-milter(8)


and that's the whole page, bestie ๐ŸŽ€ this was ClamAV 1.5.4, dated February 12, 2009 โ€” yeah she's an elder but she still ate, no cap. go forth and scan responsibly, mwah ๐Ÿ’‹๐Ÿ’–โœจ