{"componentChunkName":"component---src-templates-post-template-js","path":"/clamav-note01-en","result":{"data":{"markdownRemark":{"id":"442636eb-8676-5d23-a521-96e23e78bbed","html":"<blockquote>\n<p>This page has been machine-translated from the <a href=\"/clamav-note01\">original page</a>.</p>\n</blockquote>\n<p>In 2024, I wanted to thoroughly read the source code of a larger product, and I decided to work with AntiVirus software, which I’m most interested in.</p>\n<p>However, unfortunately, there are almost no AntiVirus Software products whose source code is publicly available.</p>\n<p>Among them, ClamAV is almost the only AntiVirus Software that is developed as open source, primarily targeting mail gateways.</p>\n<p>Although limited to Linux environments, ClamAV also has OnAccessScan (real-time scanning) functionality using fanotify, which many recent Linux AntiVirus products utilize, making it a very useful reference product.\n(ClamAV can also be used as an on-demand scanner on Windows systems.)</p>\n<p>This time, as a starting point for understanding ClamAV’s source code, I’ve summarized the build and setup procedures for ClamAV 1.2.0.</p>\n<!-- omit in toc -->\n<h2 id=\"table-of-contents\" style=\"position:relative;\"><a href=\"#table-of-contents\" aria-label=\"table of contents permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Table of Contents</h2>\n<ul>\n<li>\n<p><a href=\"#prerequisites\">Prerequisites</a></p>\n<ul>\n<li><a href=\"#build--install\">Build &#x26; Install</a></li>\n<li><a href=\"#setup\">Setup</a></li>\n<li><a href=\"#installed-modules\">Installed Modules</a></li>\n<li><a href=\"#create-service-user-account\">Create Service User Account</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#create-configuration-files\">Create Configuration Files</a></p>\n<ul>\n<li><a href=\"#edit-freshclamconf\">Edit freshclam.conf</a></li>\n<li><a href=\"#edit-clamdconf\">Edit clamd.conf</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#enable-debug-and-systemd-and-rebuild\">Enable Debug and Systemd and Rebuild</a></p>\n<ul>\n<li><a href=\"#suppress-build-warnings\">Suppress Build Warnings</a></li>\n</ul>\n</li>\n<li><a href=\"#configure-detection-notifications\">Configure Detection Notifications</a></li>\n<li><a href=\"#summary\">Summary</a></li>\n</ul>\n<h2 id=\"prerequisites\" style=\"position:relative;\"><a href=\"#prerequisites\" aria-label=\"prerequisites permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Prerequisites</h2>\n<h3 id=\"build--install\" style=\"position:relative;\"><a href=\"#build--install\" aria-label=\"build  install permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Build &#x26; Install</h3>\n<p>I used the following commands to install ClamAV on Ubuntu 20.04.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token comment\"># Run with root user in Ubuntu 20.04</span>\n<span class=\"token function\">apt-get</span> update <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">apt-get</span> <span class=\"token function\">install</span> -y gcc <span class=\"token function\">make</span> pkg-config python3 python3-pip python3-pytest valgrind cmake check libbz2-dev libcurl4-openssl-dev libjson-c-dev libmilter-dev libncurses5-dev libpcre2-dev libssl-dev libxml2-dev zlib1g-dev cargo rustc -y\n\n<span class=\"token comment\"># Install rust</span>\n<span class=\"token function\">curl</span> --proto <span class=\"token string\">'=https'</span> --tlsv1.2 -sSf https://sh.rustup.rs <span class=\"token operator\">|</span> <span class=\"token function\">sh</span>\n\n<span class=\"token comment\"># Build and install</span>\n<span class=\"token function\">git</span> clone https://github.com/Cisco-Talos/clamav.git\n<span class=\"token builtin class-name\">cd</span> clamav <span class=\"token operator\">&amp;&amp;</span> <span class=\"token function\">mkdir</span> -p build <span class=\"token operator\">&amp;&amp;</span> <span class=\"token builtin class-name\">cd</span> build\ncmake <span class=\"token punctuation\">..</span>\ncmake --build <span class=\"token builtin class-name\">.</span> --target <span class=\"token function\">install</span>\n\n<span class=\"token comment\"># Check install version</span>\nclamav-config --version</code></pre></div>\n<p>Reference: <a href=\"https://docs.clamav.net/manual/Installing/Installing-from-source-Unix.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Unix from source (v0.104+) - ClamAV Documentation</a></p>\n<p>The CMakeLists.txt file in the root directory defines the build configuration for managing the build process with CMake.</p>\n<p>For ClamAV 1.2.0, it’s approximately 1300 lines, but by skimming through it, you can get a rough overview of which files are used for the build.</p>\n<p>Reference: <a href=\"https://github.com/Cisco-Talos/clamav/blob/clamav-1.2.0/CMakeLists.txt\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">clamav/CMakeLists.txt at clamav-1.2.0 · Cisco-Talos/clamav</a></p>\n<p>In the following section, you can see that the cmake directory directly under the root is set as <code class=\"language-text\">CMAKE_MODULE_PATH</code>, and version information is included.</p>\n<div class=\"gatsby-highlight\" data-language=\";b\"><pre class=\"language-;b\"><code class=\"language-;b\">set(CMAKE_MODULE_PATH &quot;${CMAKE_CURRENT_SOURCE_DIR}/cmake&quot; ${CMAKE_MODULE_PATH})\ninclude(Version)\n\nset(PACKAGE_NAME      &quot;${PROJECT_NAME}&quot;)\nset(PACKAGE_VERSION   &quot;${PROJECT_VERSION}&quot;)\nset(PACKAGE_STRING    &quot;${PROJECT_NAME} ${PROJECT_VERSION}${VERSION_SUFFIX}&quot;)\nset(PACKAGE_BUGREPORT &quot;https://github.com/Cisco-Talos/clamav/issues&quot;)\nset(PACKAGE_URL       &quot;https://www.clamav.net/&quot;)\nHexVersion(PACKAGE_VERSION_NUM ${PROJECT_VERSION_MAJOR} ${PROJECT_VERSION_MINOR} ${PROJECT_VERSION_PATCH})</code></pre></div>\n<p>Version.cmake defines two functions: HexVersion and NumberToHex.</p>\n<p>As their names suggest, they seem to be used to convert version information values into hexadecimal strings.</p>\n<p>Reference: <a href=\"https://github.com/Cisco-Talos/clamav/blob/clamav-1.2.0/cmake/Version.cmake\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">clamav/cmake/Version.cmake at clamav-1.2.0 · Cisco-Talos/clamav</a></p>\n<p>In the following section, it identifies whether the build target platform is Linux, Unix, or macOS.</p>\n<p>For Linux, the <code class=\"language-text\">C_LINUX</code> flag is set.</p>\n<div class=\"gatsby-highlight\" data-language=\"cmake\"><pre class=\"language-cmake\"><code class=\"language-cmake\"><span class=\"token comment\"># Define C_LINUX and C_BSD because CMake only defines UNIX, APPLE, WIN32, MSVC</span>\n<span class=\"token keyword\">if</span><span class=\"token punctuation\">(</span><span class=\"token variable\">CMAKE_SYSTEM_NAME</span> <span class=\"token operator\">STREQUAL</span> <span class=\"token string\">\"Linux\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">set</span><span class=\"token punctuation\">(</span>C_LINUX <span class=\"token number\">1</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">elseif</span><span class=\"token punctuation\">(</span><span class=\"token variable\">APPLE</span> <span class=\"token operator\">OR</span> <span class=\"token variable\">CMAKE_SYSTEM_NAME</span> <span class=\"token operator\">MATCHES</span> <span class=\"token string\">\"BSD\"</span><span class=\"token punctuation\">)</span>\n    <span class=\"token keyword\">set</span><span class=\"token punctuation\">(</span>C_BSD <span class=\"token number\">1</span><span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">endif</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span></code></pre></div>\n<h3 id=\"setup\" style=\"position:relative;\"><a href=\"#setup\" aria-label=\"setup permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Setup</h3>\n<p>After installation, create the configuration files by copying the template configuration files.</p>\n<p>The default locations for ClamAV configuration files are as follows:</p>\n<ul>\n<li>freshclam configuration: <code class=\"language-text\">/usr/local/etc/freshclam.conf.sample</code></li>\n<li>clamd configuration: <code class=\"language-text\">/usr/local/etc/clamd.conf.sample</code></li>\n</ul>\n<p>Since these are sample files, copy them as follows to use them as configuration files:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">cp</span> /usr/local/etc/freshclam.conf.sample /usr/local/etc/freshclam.conf\n<span class=\"token function\">cp</span> /usr/local/etc/clamd.conf.sample /usr/local/etc/clamd.conf</code></pre></div>\n<h3 id=\"installed-modules\" style=\"position:relative;\"><a href=\"#installed-modules\" aria-label=\"installed modules permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Installed Modules</h3>\n<p>When you build and install ClamAV from source, the following files will be installed.</p>\n<p>Main executables include:</p>\n<ul>\n<li>clamscan: On-demand scanner</li>\n<li>clamdscan: On-demand scanner client for clamd daemon</li>\n<li>clamd: ClamAV daemon</li>\n<li>freshclam: Signature database update tool</li>\n<li>clamconf: Configuration check tool</li>\n<li>clamdtop: clamd monitoring tool</li>\n</ul>\n<p>And the following libraries are also installed:</p>\n<ul>\n<li>libclamav.so: ClamAV core library</li>\n<li>libfreshclam.so: Signature update library</li>\n</ul>\n<p>Reference: <a href=\"https://docs.clamav.net/manual/Usage.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Usage - ClamAV Documentation</a></p>\n<h3 id=\"create-service-user-account\" style=\"position:relative;\"><a href=\"#create-service-user-account\" aria-label=\"create service user account permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Create Service User Account</h3>\n<p>ClamAV’s daemon and related services run under the clamav user and clamav group by default.</p>\n<p>Create the clamav user account with the following command:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">groupadd</span> clamav\n<span class=\"token function\">useradd</span> -g clamav -s /bin/false -c <span class=\"token string\">\"Clam Antivirus\"</span> clamav</code></pre></div>\n<p>Also, set the appropriate permissions for the directories used by ClamAV:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">mkdir</span> -p /usr/local/var/lib/clamav\n<span class=\"token function\">chown</span> -R clamav:clamav /usr/local/var/lib/clamav\n<span class=\"token function\">mkdir</span> -p /usr/local/var/log/clamav\n<span class=\"token function\">chown</span> -R clamav:clamav /usr/local/var/log/clamav</code></pre></div>\n<h2 id=\"create-configuration-files\" style=\"position:relative;\"><a href=\"#create-configuration-files\" aria-label=\"create configuration files permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Create Configuration Files</h2>\n<h3 id=\"edit-freshclamconf\" style=\"position:relative;\"><a href=\"#edit-freshclamconf\" aria-label=\"edit freshclamconf permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Edit freshclam.conf</h3>\n<p>freshclam is a tool that automatically downloads the latest virus signature database.</p>\n<p>Edit the configuration file as follows:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">vi</span> /usr/local/etc/freshclam.conf</code></pre></div>\n<p>Key configuration items:</p>\n<div class=\"gatsby-highlight\" data-language=\"conf\"><pre class=\"language-conf\"><code class=\"language-conf\"># Comment out Example (required to use this configuration file)\n# Example\n\n# Database directory (default: /usr/local/var/lib/clamav)\nDatabaseDirectory /usr/local/var/lib/clamav\n\n# Update log file\nUpdateLogFile /usr/local/var/log/clamav/freshclam.log\n\n# Log file size limit\nLogFileMaxSize 2M\n\n# Log timestamp\nLogTime yes\n\n# syslog facility\nLogSyslog no\n\n# Run as this user\nDatabaseOwner clamav\n\n# Database mirror (default: database.clamav.net)\nDatabaseMirror database.clamav.net</code></pre></div>\n<p>After editing, run freshclam to download the signature database:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">freshclam</code></pre></div>\n<p>If the update is successful, you should see output like:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">ClamAV update process started at Sun Jan <span class=\"token number\">28</span> <span class=\"token number\">10</span>:00:00 <span class=\"token number\">2024</span>\ndaily.cvd database is up-to-date <span class=\"token punctuation\">(</span>version: <span class=\"token number\">27120</span>, sigs: <span class=\"token number\">2050127</span>, f-level: <span class=\"token number\">90</span>, builder: raynman<span class=\"token punctuation\">)</span>\nmain.cvd database is up-to-date <span class=\"token punctuation\">(</span>version: <span class=\"token number\">62</span>, sigs: <span class=\"token number\">6647427</span>, f-level: <span class=\"token number\">90</span>, builder: sigmgr<span class=\"token punctuation\">)</span>\nbytecode.cvd database is up-to-date <span class=\"token punctuation\">(</span>version: <span class=\"token number\">334</span>, sigs: <span class=\"token number\">91</span>, f-level: <span class=\"token number\">90</span>, builder: anvilleg<span class=\"token punctuation\">)</span></code></pre></div>\n<h3 id=\"edit-clamdconf\" style=\"position:relative;\"><a href=\"#edit-clamdconf\" aria-label=\"edit clamdconf permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Edit clamd.conf</h3>\n<p>clamd is the ClamAV daemon that provides the scanning service.</p>\n<p>Edit the configuration file as follows:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">vi</span> /usr/local/etc/clamd.conf</code></pre></div>\n<p>Key configuration items:</p>\n<div class=\"gatsby-highlight\" data-language=\"conf\"><pre class=\"language-conf\"><code class=\"language-conf\"># Comment out Example (required to use this configuration file)\n# Example\n\n# Log file\nLogFile /usr/local/var/log/clamav/clamd.log\n\n# Log timestamp\nLogTime yes\n\n# Log file size limit\nLogFileMaxSize 2M\n\n# Run as this user\nUser clamav\n\n# Unix socket path\nLocalSocket /usr/local/var/run/clamav/clamd.sock\n\n# Fix stale socket issues\nFixStaleSocket yes\n\n# TCP socket settings (if you want to use TCP instead of Unix socket)\n# TCPSocket 3310\n# TCPAddr 127.0.0.1\n\n# Maximum number of threads for scanning\nMaxThreads 12\n\n# Maximum queue length\nMaxQueue 100\n\n# Idle timeout\nIdleTimeout 30\n\n# Exclude certain paths from scanning (use with OnAccessScan)\nExcludePath ^/proc/\nExcludePath ^/sys/\n\n# OnAccessScan settings\nOnAccessMountPath /home\nOnAccessIncludePath /home\nOnAccessExcludePath /home/clamav\nOnAccessPrevention no\nOnAccessExtraScanning yes</code></pre></div>\n<p>Create the necessary directory for the Unix socket:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">mkdir</span> -p /usr/local/var/run/clamav\n<span class=\"token function\">chown</span> -R clamav:clamav /usr/local/var/run/clamav</code></pre></div>\n<h2 id=\"enable-debug-and-systemd-and-rebuild\" style=\"position:relative;\"><a href=\"#enable-debug-and-systemd-and-rebuild\" aria-label=\"enable debug and systemd and rebuild permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Enable Debug and Systemd and Rebuild</h2>\n<p>To enable debugging and systemd support, rebuild ClamAV with additional options.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token builtin class-name\">cd</span> /path/to/clamav/build\ncmake <span class=\"token punctuation\">..</span> -D <span class=\"token assign-left variable\">CMAKE_BUILD_TYPE</span><span class=\"token operator\">=</span>Debug -D <span class=\"token assign-left variable\">ENABLE_SYSTEMD</span><span class=\"token operator\">=</span>ON\ncmake --build <span class=\"token builtin class-name\">.</span> --target <span class=\"token function\">install</span></code></pre></div>\n<p>The Debug build type includes debugging symbols and disables optimization, making it easier to debug.</p>\n<p>With systemd support enabled, you can register clamd and freshclam as systemd services.</p>\n<h3 id=\"suppress-build-warnings\" style=\"position:relative;\"><a href=\"#suppress-build-warnings\" aria-label=\"suppress build warnings permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Suppress Build Warnings</h3>\n<p>If you encounter build warnings, you can suppress specific warnings by adding flags to CMakeLists.txt.</p>\n<p>For example, to suppress deprecation warnings:</p>\n<div class=\"gatsby-highlight\" data-language=\"cmake\"><pre class=\"language-cmake\"><code class=\"language-cmake\"><span class=\"token keyword\">add_compile_options</span><span class=\"token punctuation\">(</span>-Wno-deprecated-declarations<span class=\"token punctuation\">)</span></code></pre></div>\n<h2 id=\"configure-detection-notifications\" style=\"position:relative;\"><a href=\"#configure-detection-notifications\" aria-label=\"configure detection notifications permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Configure Detection Notifications</h2>\n<p>When ClamAV detects malware, you can configure it to execute a specified script or send notifications.</p>\n<p>Configure in clamd.conf:</p>\n<div class=\"gatsby-highlight\" data-language=\"conf\"><pre class=\"language-conf\"><code class=\"language-conf\"># Command to execute when a virus is detected\nVirusEvent /usr/local/bin/virus_alert.sh %v %f</code></pre></div>\n<ul>\n<li><code class=\"language-text\">%v</code>: Virus name</li>\n<li><code class=\"language-text\">%f</code>: Infected file path</li>\n</ul>\n<p>Example notification script:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token shebang important\">#!/bin/bash</span>\n<span class=\"token assign-left variable\">VIRUS</span><span class=\"token operator\">=</span><span class=\"token variable\">$1</span>\n<span class=\"token assign-left variable\">FILE</span><span class=\"token operator\">=</span><span class=\"token variable\">$2</span>\n<span class=\"token assign-left variable\">DATE</span><span class=\"token operator\">=</span><span class=\"token variable\"><span class=\"token variable\">$(</span><span class=\"token function\">date</span><span class=\"token variable\">)</span></span>\n<span class=\"token builtin class-name\">echo</span> <span class=\"token string\">\"<span class=\"token variable\">$DATE</span> - Virus detected: <span class=\"token variable\">$VIRUS</span> in file <span class=\"token variable\">$FILE</span>\"</span> <span class=\"token operator\">>></span> /var/log/clamav/virus_detected.log\n<span class=\"token comment\"># Add notification logic here (email, Slack, etc.)</span></code></pre></div>\n<p>Make the script executable:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token function\">chmod</span> +x /usr/local/bin/virus_alert.sh</code></pre></div>\n<h2 id=\"summary\" style=\"position:relative;\"><a href=\"#summary\" aria-label=\"summary permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Summary</h2>\n<p>In this article, I summarized the steps to build ClamAV 1.2.0 from source code and set up OnAccessScan.</p>\n<p>Key points covered:</p>\n<ol>\n<li>Installing dependencies and building ClamAV from source</li>\n<li>Creating and configuring freshclam.conf and clamd.conf</li>\n<li>Creating service user accounts and setting directory permissions</li>\n<li>Enabling debug mode and systemd support</li>\n<li>Configuring detection notifications</li>\n</ol>\n<p>ClamAV is a valuable resource for learning about AntiVirus implementation, especially the fanotify-based OnAccessScan feature on Linux.</p>\n<p>In future articles, I plan to dive deeper into ClamAV’s source code to understand its internal architecture and scanning mechanisms.</p>","fields":{"slug":"/clamav-note01-en","tagSlugs":["/tag/clam-av/","/tag/malware/","/tag/english/"]},"frontmatter":{"date":"2024-01-27","description":"Summary of the steps to build ClamAV from source code and set up OnAccessScan.","tags":["ClamAV","Malware","English"],"title":"Summary of Building ClamAV from Source Code and Setting Up OnAccessScan","socialImage":{"publicURL":"/static/34516ec698c27cd04cfd176d8c426baf/clamav-note01.png"}}}},"pageContext":{"slug":"/clamav-note01-en"}},"staticQueryHashes":["251939775","401334301","825871152"]}